Sha256: 3e6f0e233efef2450bbd7e75dd9d1445522dd5b36a771a3989c9a209aebb9a16

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require_relative '../../puppet/ssl/openssl_loader'
require 'net/http'
require_relative '../../puppet/http'

# Factory for `Net::HTTP` objects.
#
# Encapsulates the logic for creating a `Net::HTTP` object based on the
# specified {Site} and puppet settings.
#
# @api private
class Puppet::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::HTTP::Proxy.proxy(URI(site.addr))
    http.use_ssl = site.use_ssl?
    if site.use_ssl?
      http.min_version = OpenSSL::SSL::TLS1_VERSION if http.respond_to?(:min_version)
      http.ciphers = Puppet[:ciphers]
    end
    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=)

    # 0 means make one request and never retry
    http.max_retries = 0

    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

8 entries across 8 versions & 1 rubygems

Version Path
puppet-8.5.1 lib/puppet/http/factory.rb
puppet-8.5.1-x86-mingw32 lib/puppet/http/factory.rb
puppet-8.5.1-x64-mingw32 lib/puppet/http/factory.rb
puppet-8.5.1-universal-darwin lib/puppet/http/factory.rb
puppet-8.5.0 lib/puppet/http/factory.rb
puppet-8.5.0-x86-mingw32 lib/puppet/http/factory.rb
puppet-8.5.0-x64-mingw32 lib/puppet/http/factory.rb
puppet-8.5.0-universal-darwin lib/puppet/http/factory.rb