connection_for(uri)
public
Creates or an HTTP connection based on uri, or retrieves an
existing connection, using a proxy if needed.
# File lib/rubygems/remote_fetcher.rb, line 306
def connection_for(uri)
net_http_args = [uri.host, uri.port]
if @proxy_uri then
net_http_args += [
@proxy_uri.host,
@proxy_uri.port,
@proxy_uri.user,
@proxy_uri.password
]
end
connection_id = [Thread.current.object_id, *net_http_args].join ':'
@connections[connection_id] ||= Net::HTTP.new(*net_http_args)
connection = @connections[connection_id]
if https?(uri) and !connection.started? then
configure_connection_for_https(connection)
end
connection.start unless connection.started?
connection
rescue OpenSSL::SSL::SSLError, Errno::EHOSTDOWN => e
raise FetchError.new(e.message, uri)
end