public Method

HTTP.open( host, port )

Return a new socket connected to the given host and port via the proxy that was requested when the socket factory was instantiated.

Source Code

# File net/ssh/proxy/http.rb, line 42
def open( host, port )
  connect_string = "CONNECT #{host}:#{port} HTTP/1.0"

  socket = TCPSocket.new( @proxy_host, @proxy_port )
  socket.puts connect_string
  socket.puts

  resp = parse_response( socket )

  return socket if resp[:code] == 200

  socket.shutdown
  raise ConnectError, resp.inspect unless resp[:code] == 407

  user = proxy_user
  passwd = proxy_password

  raise UnauthorizedError, "no proxy user given" unless user

  auth = resp[:headers]["Proxy-Authenticate"]
  scheme, parms = auth.split( / /, 2 )

  case scheme
    when "Basic"
      credentials =
        Base64.encode64( "#{user}:#{passwd}" ).gsub( /\n/, "" )
    else
      raise NotImplementedError,
        "authorization scheme #{scheme.inspect} is not supported"
  end

  socket = TCPSocket.new( @proxy_host, @proxy_port )
  socket.puts connect_string
  socket.puts "Proxy-Authorization: #{scheme} #{credentials}"
  socket.puts

  resp = parse_response( socket )

  raise ConnectError, resp.inspect if resp[:code] != 200

  return socket
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.