class Gem::Net::HTTP::Persistent

def connection_for uri

def connection_for uri
  use_ssl = uri.scheme.downcase == 'https'
  net_http_args = [uri.hostname, uri.port]
  # I'm unsure if uri.host or uri.hostname should be checked against
  # the proxy bypass list.
  if @proxy_uri and not proxy_bypass? uri.host, uri.port then
    net_http_args.concat @proxy_args
  else
    net_http_args.concat [nil, nil, nil, nil]
  end
  connection = @pool.checkout net_http_args
  http = connection.http
  connection.ressl @ssl_generation if
    connection.ssl_generation != @ssl_generation
  if not http.started? then
    ssl   http if use_ssl
    start http
  elsif expired? connection then
    reset connection
  end
  http.keep_alive_timeout = @idle_timeout  if @idle_timeout
  http.max_retries        = @max_retries   if http.respond_to?(:max_retries=)
  http.read_timeout       = @read_timeout  if @read_timeout
  http.write_timeout      = @write_timeout if
    @write_timeout && http.respond_to?(:write_timeout=)
  return yield connection
rescue Errno::ECONNREFUSED
  address = http.proxy_address || http.address
  port    = http.proxy_port    || http.port
  raise Error, "connection refused: #{address}:#{port}"
rescue Errno::EHOSTDOWN
  address = http.proxy_address || http.address
  port    = http.proxy_port    || http.port
  raise Error, "host down: #{address}:#{port}"
ensure
  @pool.checkin net_http_args
end