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