Method: Async::HTTP::Proxy#connect

Defined in:
lib/async/http/proxy.rb

#connect(&block) ⇒ Socket

Establish a TCP connection to the specified host.

Returns:

  • (Socket)

    a connected bi-directional socket.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/async/http/proxy.rb', line 82

def connect(&block)
  input = Body::Writable.new
  
  response = @client.connect(authority: @address, headers: @headers, body: input)
  
  if response.success?
    pipe = Body::Pipe.new(response.body, input)
    
    return pipe.to_io unless block_given?
    
    begin
      yield pipe.to_io
    ensure
      pipe.close
    end
  else
    # This ensures we don't leave a response dangling:
    input.close
    response.close
    
    raise ConnectFailure, response
  end
end