Method: HTTPX::TCP#initialize

Defined in:
lib/httpx/io/tcp.rb

#initialize(uri, options) ⇒ TCP

Returns a new instance of TCP.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/httpx/io/tcp.rb', line 14

def initialize(uri, options)
  @state = :idle
  @hostname = uri.host
  @options = Options.new(options)
  @fallback_protocol = @options.fallback_protocol
  @port = uri.port
  if @options.io
    @io = case @options.io
          when Hash
            @ip = Resolv.getaddress(@hostname)
            @options.io[@ip] || @options.io["#{@ip}:#{@port}"]
          else
            @ip = @hostname
            @options.io
    end
    unless @io.nil?
      @keep_open = true
      @state = :connected
    end
  else
    @ip = Resolv.getaddress(@hostname)
  end
  @io ||= build_socket
end