class AWS::Core::Http::ConnectionPool

@api private
@attr_reader [String,nil] ssl_ca_path
@attr_reader [String,nil] ssl_ca_file
@attr_reader [Boolean] ssl_verify_peer
@attr_reader [Logger,nil] logger
@attr_reader [Boolean] http_wire_trace
@attr_reader [Integer,Float] http_read_timeout
@attr_reader [Integer,Float] http_open_timeout
@attr_reader [Integer,Float] http_idle_timeout
@attr_reader [Float,nil] http_continue_timeout
@attr_reader [URI::HTTP,nil] proxy_uri Returns the configured proxy uri.

def _clean

Other tags:
    Note: - **Must** be called behind a `@pool_mutex` synchronize block.
def _clean
  now = Time.now
  @pool.each_pair do |endpoint,sessions|
    sessions.delete_if do |session|
      if
        session.last_used.nil? or
        now - session.last_used > http_idle_timeout
      then
        session.finish
        true
      end
    end
  end
end

def clean!

Returns:
  • (nil) -
def clean!
  @pool_mutex.synchronize { _clean }
  nil
end

def empty!

Returns:
  • (nil) -
def empty!
  @pool_mutex.synchronize do
    @pool.each_pair do |endpoint,sessions|
      sessions.each(&:finish)
    end
    @pool.clear
  end
  nil
end

def initialize options = {}

Other tags:
    Api: - private
def initialize options = {}
  # user supplied options are filtered by the class .for method
  options.each_pair do |opt_name, opt_value|
    instance_variable_set("@#{opt_name}", opt_value)
  end
  # connection pool
  @pool_mutex = Mutex.new
  @pool = Hash.new do |pool,endpoint|
    pool[endpoint] = []
    pool[endpoint]
  end
end

def new options = {}

Returns:
  • (ConnectionPool) -

Options Hash: (**options)
  • :ssl_ca_path (String) -- Full path of the directory
  • :ssl_ca_file (String) -- Full path to the SSL
  • :ssl_verify_peer (Boolean) -- When `true`, SSL
  • :logger (Logger) -- Where debug output is sent.
  • :http_wire_trace (Boolean) -- When `true`, HTTP
  • :http_read_timeout (Integer) -- The default
  • :http_open_timeout (Float) -- The number of
  • :http_idle_timeout (Float) -- The number of
  • :http_continue_timeout (Float) -- The number of
  • :proxy_uri (URI::HTTP, String) -- A proxy to send
def new options = {}
  options = pool_options(options)
  @pools_mutex.synchronize do
    @pools[options] ||= super(options)
  end
end

def options

Returns:
  • (Hash) - a read-only hash of options for this pool.
def options
  OPTIONS.inject({}) do |options, opt_name|
    options[opt_name] = send(opt_name)
    options
  end.freeze
end

def pool_options options

Returns:
  • (Hash) -
def pool_options options
  wire_trace = !!options[:http_wire_trace]
  logger = options[:logger] || Logger.new($stdout) if wire_trace
  verify_peer = options.key?(:ssl_verify_peer) ?
    !!options[:ssl_verify_peer] : true
  {
    :proxy_uri => URI.parse(options[:proxy_uri].to_s),
    :http_continue_timeout => options[:http_continue_timeout],
    :http_open_timeout => options[:http_open_timeout] || 15,
    :http_idle_timeout => options[:http_idle_timeout] || 15,
    :http_read_timeout => options[:http_read_timeout] || 60,
    :http_wire_trace => wire_trace,
    :logger => logger,
    :ssl_verify_peer => verify_peer,
    :ssl_ca_file => options[:ssl_ca_file],
    :ssl_ca_path => options[:ssl_ca_path],
  }
end

def pools

Returns:
  • (Array) - Returns a list of of the constructed
def pools
  @pools.values
end

def request endpoint, request, &block

Returns:
  • (see #session_for) - see #session_for

Other tags:
    Yieldparam: net_http_response -

Parameters:
  • request (Net::HTTPRequest) -- The request to make. This can be
  • endpoint (URI::HTTP, URI::HTTPS, String) -- The HTTP(S) endpoint to
def request endpoint, request, &block
  session_for(endpoint) do |http|
    yield(http.request(request))
  end
end

def session_for endpoint, &block

Returns:
  • (nil) -

Other tags:
    Yieldparam: session -

Parameters:
  • endpoint (URI::HTTP, URI::HTTPS, String) -- The HTTP(S) endpoint to
def session_for endpoint, &block
  endpoint = endpoint.to_s
  session = nil
  # attempt to recycle an already open session
  @pool_mutex.synchronize do
    _clean
    session = @pool[endpoint].shift
  end
  begin
    session ||= start_session(endpoint)
    session.read_timeout = http_read_timeout
    session.continue_timeout = http_continue_timeout if
      session.respond_to?(:continue_timeout=)
    yield(session)
  rescue Exception => error
    session.finish if session
    raise error
  else
    # No error raised? Good, check the session into the pool.
    @pool_mutex.synchronize { @pool[endpoint] << session }
  end
  nil
end

def size

Returns:
  • (Integer) - Returns the count of sessions currently in the pool,
def size
  @pool_mutex.synchronize do
    size = 0
    @pool.each_pair do |endpoint,sessions|
      size += sessions.size
    end
    size
  end
end

def start_session endpoint

Returns:
  • (Net::HTTPSession) -

Parameters:
  • endpoint (String) --
def start_session endpoint
  endpoint = URI.parse(endpoint)
  args = []
  args << endpoint.host
  args << endpoint.port
  args << proxy_uri.host
  args << proxy_uri.port
  args << proxy_uri.user
  args << proxy_uri.password
  http = Net::HTTP.new(*args.compact)
  http.extend(SessionExtensions)
  http.set_debug_output(logger) if http_wire_trace?
  http.open_timeout = http_open_timeout
  if endpoint.scheme == 'https'
    http.use_ssl = true
    if ssl_verify_peer?
      http.verify_mode = OpenSSL::SSL::VERIFY_PEER
      http.ca_file = ssl_ca_file if ssl_ca_file
      http.ca_path = ssl_ca_path if ssl_ca_path
    else
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
  else
    http.use_ssl = false
  end
  http.start
  http
end