Method: Gem::Net::HTTP::Persistent#initialize

Defined in:
lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb

#initialize(name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE) ⇒ Persistent

Creates a new Gem::Net::HTTP::Persistent.

Set a name for fun. Your library name should be good enough, but this otherwise has no purpose.

proxy may be set to a Gem::URI::HTTP or :ENV to pick up proxy options from the environment. See proxy_from_env for details.

In order to use a Gem::URI for the proxy you may need to do some extra work beyond Gem::URI parsing if the proxy requires a password:

proxy = Gem::URI 'http://proxy.example'
proxy.user     = 'AzureDiamond'
proxy.password = 'hunter2'

Set pool_size to limit the maximum number of connections allowed. Defaults to 1/4 the number of allowed file handles or 256 if your OS does not support a limit on allowed file handles. You can have no more than this many threads with active HTTP transactions.



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb', line 490

def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
  @name = name

  @debug_output     = nil
  @proxy_uri        = nil
  @no_proxy         = []
  @headers          = {}
  @override_headers = {}
  @http_versions    = {}
  @keep_alive       = 30
  @open_timeout     = nil
  @read_timeout     = nil
  @write_timeout    = nil
  @idle_timeout     = 5
  @max_requests     = nil
  @max_retries      = 1
  @socket_options   = []
  @ssl_generation   = 0 # incremented when SSL session variables change

  @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
    Socket.const_defined? :TCP_NODELAY

  @pool = Gem::Net::HTTP::Persistent::Pool.new size: pool_size do |http_args|
    Gem::Net::HTTP::Persistent::Connection.new Gem::Net::HTTP, http_args, @ssl_generation
  end

  @certificate        = nil
  @ca_file            = nil
  @ca_path            = nil
  @ciphers            = nil
  @private_key        = nil
  @ssl_timeout        = nil
  @ssl_version        = nil
  @min_version        = nil
  @max_version        = nil
  @verify_callback    = nil
  @verify_depth       = nil
  @verify_mode        = nil
  @verify_hostname    = nil
  @cert_store         = nil

  @generation         = 0 # incremented when proxy Gem::URI changes

  if HAVE_OPENSSL then
    @verify_mode        = OpenSSL::SSL::VERIFY_PEER
    @reuse_ssl_sessions = OpenSSL::SSL.const_defined? :Session
  end

  self.proxy = proxy if proxy
end