class Async::HTTP::Proxy
Behaves like a TCP endpoint for the purposes of connecting to a remote host.
Wraps a client, address and headers required to initiate a connectio to a remote host using the CONNECT verb.
def self.endpoint(client, endpoint, headers = nil)
-
headers
(Array
) -- an optional list of headers to use when establishing the connection. -
endpoint
(Async::HTTP::Endpoint
) -- the endpoint to connect to. -
client
(Async::HTTP::Client
) -- the client which will be used as a proxy server.
def self.endpoint(client, endpoint, headers = nil) proxy = self.new(client, endpoint.authority(false), headers) return proxy.endpoint(endpoint.url) end
def self.tcp(client, host, port, headers = nil)
- See: Async::IO::Endpoint#tcp -
Parameters:
-
headers
(Array
) -- an optional list of headers to use when establishing the connection. -
port
(String
) -- the port number to connect to. -
host
(String
) -- the hostname or address to connect to. -
client
(Async::HTTP::Client
) -- the client which will be used as a proxy server.
def self.tcp(client, host, port, headers = nil) self.new(client, "#{host}:#{port}", headers) end
def close
def close @client.close end
def connect(&block)
-
(Socket)
- a connected bi-directional socket.
def connect(&block) input = Body::Writable.new response = @client.connect(@address.to_s, @headers, input) pipe = Body::Pipe.new(response.body, input) return pipe.to_io unless block_given? begin yield pipe.to_io ensure pipe.close end end
def initialize(client, address, headers = nil)
-
headers
(Array
) -- an optional list of headers to use when establishing the connection. -
address
(String
) -- the address to connect to. -
client
(Async::HTTP::Client
) -- the client which will be used as a proxy server.
def initialize(client, address, headers = nil) @client = client @address = address @headers = ::Protocol::HTTP::Headers[headers].freeze end
def wrap_endpoint(endpoint)
-
(Async::HTTP::Endpoint)
- an endpoint that connects via the specified proxy.
def wrap_endpoint(endpoint) Endpoint.new(endpoint.url, self, **endpoint.options) end