Sha256: 2bc1c8e0a2014808ca2dc285fa0d85a79d25690ad3c08bc27ab9443c5182f889

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

require "forwardable"

module HTTP
  module Timeout
    class Null
      extend Forwardable

      def_delegators :@socket, :close, :closed?

      attr_reader :options, :socket

      def initialize(options = {})
        @options = options
      end

      # Connects to a socket
      def connect(socket_class, host, port)
        @socket = socket_class.open(host, port)
      end

      # Starts a SSL connection on a socket
      def connect_ssl
        @socket.connect
      end

      # Configures the SSL connection and starts the connection
      def start_tls(host, ssl_socket_class, ssl_context)
        @socket = ssl_socket_class.new(socket, ssl_context)
        @socket.sync_close = true if @socket.respond_to? :sync_close=

        connect_ssl

        return unless ssl_context.verify_mode == OpenSSL::SSL::VERIFY_PEER

        @socket.post_connection_check(host)
      end

      # Read from the socket
      def readpartial(size)
        @socket.readpartial(size)
      end

      # Write to the socket
      def write(data)
        @socket << data
      end

      alias_method :<<, :write
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
http-0.8.10 lib/http/timeout/null.rb
http-0.8.9 lib/http/timeout/null.rb
http-0.8.8 lib/http/timeout/null.rb
http-0.8.7 lib/http/timeout/null.rb
http-0.8.6 lib/http/timeout/null.rb
http-0.8.5 lib/http/timeout/null.rb
http-0.8.4 lib/http/timeout/null.rb
http-0.8.3 lib/http/timeout/null.rb
http-0.8.2 lib/http/timeout/null.rb