Method: Net::SSH::Proxy::HTTP#open
- Defined in:
- lib/net/ssh/proxy/http.rb
#open(host, port, connection_options) ⇒ Object
Return a new socket connected to the given host and port via the proxy that was requested when the socket factory was instantiated.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/net/ssh/proxy/http.rb', line 52 def open(host, port, ) socket = establish_connection([:timeout]) socket.write "CONNECT #{host}:#{port} HTTP/1.1\r\n" socket.write "Host: #{host}:#{port}\r\n" if [:user] credentials = ["#{[:user]}:#{[:password]}"].pack("m*").gsub(/\s/, "") socket.write "Proxy-Authorization: Basic #{credentials}\r\n" end socket.write "\r\n" resp = parse_response(socket) return socket if resp[:code] == 200 socket.close raise ConnectError, resp.inspect end |