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
16 def initialize
17   # PUP-1411, make sure that openssl is initialized before we try to connect
18   if ! @@openssl_initialized
19     OpenSSL::SSL::SSLContext.new
20     @@openssl_initialized = true
21   end
22 end

Public Instance Methods

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