class Puppet::HTTP::Factory

Factory for `Net::HTTP` objects.

Encapsulates the logic for creating a `Net::HTTP` object based on the specified {Site} and puppet settings.

@api private

Constants

KEEP_ALIVE_TIMEOUT

Public Class Methods

new() click to toggle source
   # File lib/puppet/http/factory.rb
17 def initialize
18   # PUP-1411, make sure that openssl is initialized before we try to connect
19   if ! @@openssl_initialized
20     OpenSSL::SSL::SSLContext.new
21     @@openssl_initialized = true
22   end
23 end

Public Instance Methods

create_connection(site) click to toggle source
   # File lib/puppet/http/factory.rb
25 def create_connection(site)
26   Puppet.debug("Creating new connection for #{site}")
27 
28   http = Puppet::HTTP::Proxy.proxy(URI(site.addr))
29   http.use_ssl = site.use_ssl?
30   if site.use_ssl?
31     http.min_version = OpenSSL::SSL::TLS1_VERSION if http.respond_to?(:min_version)
32     http.ciphers = Puppet[:ciphers]
33   end
34   http.read_timeout = Puppet[:http_read_timeout]
35   http.open_timeout = Puppet[:http_connect_timeout]
36   http.keep_alive_timeout = KEEP_ALIVE_TIMEOUT if http.respond_to?(:keep_alive_timeout=)
37 
38   # 0 means make one request and never retry
39   http.max_retries = 0
40 
41   if Puppet[:sourceaddress]
42     Puppet.debug("Using source IP #{Puppet[:sourceaddress]}")
43     http.local_host = Puppet[:sourceaddress]
44   end
45 
46   if Puppet[:http_debug]
47     http.set_debug_output($stderr)
48   end
49 
50   http
51 end