class Net::HTTP::ConnectionPool::Connection

A light wrapper around Net::HTTP.

You should not need to construct connection objects yourself.

You receive them as a response to {Net::HTTP::ConnectionPool#connection_for}.

Attributes

host[R]

@return [String]

pool[R]

@return [ConnectionPool]

port[R]

@return [Integer]

proxy_address[R]

@return [String,nil]

proxy_password[R]

@return [String,nil]

proxy_port[R]

@return [Integer,nil]

proxy_user[R]

@return [String,nil]

read_timeout[RW]

@return [Numeric,nil]

ssl[R]

@return [Boolean]

ssl_ca_file[R]

@return [String,nil]

ssl_ca_path[R]

@return [String,nil]

ssl_verify_peer[R]

@return [Boolean]

Public Class Methods

new(pool, host, options = {}) click to toggle source

@param [ConnectionPool] pool @param (see Net::HTTP::ConnectionPool#connection_for) @option (see Net::HTTP::ConnectionPool#connection_for) @return [Connection]

# File lib/net/http/connection_pool/connection.rb, line 29
def initialize pool, host, options = {}

  @pool = pool

  @host = host

  @port = options.key?(:port) ? options[:port] : (options[:ssl] ? 443 : 80)

  @ssl = options.key?(:ssl) ? options[:ssl] : (port == 443) 

  @ssl_verify_peer = options.key?(:ssl_verify_peer) ?
    options[:ssl_verify_peer] : true

  @ssl_ca_file = options[:ssl_ca_file]

  @ssl_ca_path = options[:ssl_ca_path]

  if uri = options[:proxy_uri]
    uri = URI.parse(uri) if uri.is_a?(String)
    @proxy_address = uri.host
    @proxy_port = uri.port
    @proxy_user = uri.user
    @proxy_password = uri.password
  else
    @proxy_address = options[:proxy_address]
    @proxy_port = options[:proxy_port]
    @proxy_user = options[:proxy_user]
    @proxy_password = options[:proxy_password]
  end

  @read_timeout = options[:read_timeout] || 60

end

Public Instance Methods

key() click to toggle source

@return [String] Returns a key that can be used to group connections

that connection to the same host.
# File lib/net/http/connection_pool/connection.rb, line 121
def key
  @key ||= begin
    %w(
      host port 
      ssl ssl_verify_peer ssl_ca_file ssl_ca_path
      proxy_address proxy_port proxy_user proxy_password
    ).map{|part| send(part).to_s }.join(":")
  end
end
proxy?() click to toggle source

@return [Boolean] Returns true if this connection proxies requests.

# File lib/net/http/connection_pool/connection.rb, line 111
def proxy?
  !!proxy_address
end
request(*args, &block) click to toggle source
# File lib/net/http/connection_pool/connection.rb, line 115
def request *args, &block
  pool.request(self, *args, &block)
end
ssl?() click to toggle source

@return [Boolean] Returns true if this connection requires SSL.

# File lib/net/http/connection_pool/connection.rb, line 100
def ssl?
  @ssl
end
ssl_verify_peer?() click to toggle source

@return [Boolean] Returns true if ssl connections should verify the

peer certificate.
# File lib/net/http/connection_pool/connection.rb, line 106
def ssl_verify_peer?
  @ssl_verify_peer
end