Sha256: 6f106d3a58a8d2a23af5ea21e5f709134d0d42ea6f66e1e31386766e03a07f80

Contents?: true

Size: 1.34 KB

Versions: 24

Compression:

Stored size: 1.34 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}")

    http = Puppet::Util::HttpProxy.proxy(URI(site.addr))
    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 Puppet[:sourceaddress]
      if http.respond_to?(:local_host)
        Puppet.debug("Using source IP #{Puppet[:sourceaddress]}")
        http.local_host = Puppet[:sourceaddress]
      else
        raise ArgumentError, "Setting 'sourceaddress' is unsupported by this version of Net::HTTP."
      end
    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-5.5.22 lib/puppet/network/http/factory.rb
puppet-5.5.22-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.22-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.22-universal-darwin lib/puppet/network/http/factory.rb
puppet-5.5.21 lib/puppet/network/http/factory.rb
puppet-5.5.21-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.21-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.21-universal-darwin lib/puppet/network/http/factory.rb
puppet-5.5.20 lib/puppet/network/http/factory.rb
puppet-5.5.20-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.20-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.20-universal-darwin lib/puppet/network/http/factory.rb
puppet-5.5.19 lib/puppet/network/http/factory.rb
puppet-5.5.19-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.19-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.19-universal-darwin lib/puppet/network/http/factory.rb
puppet-5.5.18 lib/puppet/network/http/factory.rb
puppet-5.5.18-x86-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.18-x64-mingw32 lib/puppet/network/http/factory.rb
puppet-5.5.18-universal-darwin lib/puppet/network/http/factory.rb