Sha256: f54f8089a5ce2ba0a57adbaa156a728e651dd4fad6e044c3b2d04ab7742a8eb0

Contents?: true

Size: 1.53 KB

Versions: 24

Compression:

Stored size: 1.53 KB

Contents

require 'openssl'
require 'net/http'
require 'puppet/util/http_proxy'

# Factory for <tt>Net::HTTP</tt> objects.
#
# Encapsulates the logic for creating a <tt>Net::HTTP</tt> object based on the
# specified {Puppet::Network::HTTP::Site Site} and puppet settings.
#
# @api private
#
class Puppet::Network::HTTP::Factory
  @@openssl_initialized = false

  KEEP_ALIVE_TIMEOUT = 2**31 - 1

  def initialize
    # PUP-1411, make sure that openssl is initialized before we try to connect
    if ! @@openssl_initialized
      OpenSSL::SSL::SSLContext.new
      @@openssl_initialized = true
    end
  end

  def create_connection(site)
    Puppet.debug("Creating new connection for #{site}")

    args = [site.host, site.port]

    unless Puppet::Util::HttpProxy.no_proxy?(site)
      if Puppet[:http_proxy_host] == "none"
        args << nil << nil
      else
        args << Puppet[:http_proxy_host] << Puppet[:http_proxy_port]
      end
    end

    http = Net::HTTP.new(*args)
    http.use_ssl = site.use_ssl?
    http.read_timeout = Puppet[:http_read_timeout]
    http.open_timeout = Puppet[:http_connect_timeout]
    http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT if http.respond_to?(:keep_alive_timeout=)

    if http.respond_to?(:max_retries)
      # 0 means make one request and never retry
      http.max_retries = 0
    end

    if Puppet[:sourceaddress]
      Puppet.debug("Using source IP #{Puppet[:sourceaddress]}")
      http.local_host = Puppet[:sourceaddress]
    end

    if Puppet[:http_debug]
      http.set_debug_output($stderr)
    end

    http
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
puppet-6.7.2 lib/puppet/network/http/factory.rb
puppet-6.7.2-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-6.7.2-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-6.7.2-universal-darwin lib/puppet/network/http/factory.rb
puppet-6.7.0 lib/puppet/network/http/factory.rb
puppet-6.7.0-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-6.7.0-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-6.7.0-universal-darwin lib/puppet/network/http/factory.rb
puppet-6.4.3 lib/puppet/network/http/factory.rb
puppet-6.4.3-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-6.4.3-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-6.4.3-universal-darwin lib/puppet/network/http/factory.rb
puppet-6.0.10 lib/puppet/network/http/factory.rb
puppet-6.0.10-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-6.0.10-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-6.0.10-universal-darwin lib/puppet/network/http/factory.rb
puppet-6.6.0 lib/puppet/network/http/factory.rb
puppet-6.6.0-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-6.6.0-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-6.6.0-universal-darwin lib/puppet/network/http/factory.rb