def connection_for uri
    use_ssl = uri.scheme.downcase == 'https'

    net_http_args = [uri.host, uri.port]

    net_http_args.concat @proxy_args if
      @proxy_uri and not proxy_bypass? uri.host, uri.port

    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.read_timeout = @read_timeout if @read_timeout
    http.keep_alive_timeout = @idle_timeout if @idle_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
    # Only perform checkin if we successfully checked a connection out
    if connection
      @pool.checkin net_http_args
    end
  end
def connection_for uri
    use_ssl = uri.scheme.downcase == 'https'

    net_http_args = [uri.host, uri.port]

    net_http_args.concat @proxy_args if
      @proxy_uri and not proxy_bypass? uri.host, uri.port

    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.read_timeout = @read_timeout if @read_timeout
    http.keep_alive_timeout = @idle_timeout if @idle_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
    # Only perform checkin if we successfully checked a connection out
    if connection
      @pool.checkin net_http_args
    end
  end
Creates a new connection for +uri+