Module: Puppet::Network::HttpPool

Extended by:
Util::Cacher
Defined in:
lib/puppet/network/http_pool.rb

Overview

Manage Net::HTTP instances for keep-alive.

Constant Summary collapse

HTTP_KEEP_ALIVE =

2008/03/23 LAK:WARNING: Enabling this has a high propability of causing corrupt files and who knows what else. See #1010.

false

Instance Attribute Summary

Attributes included from Util::Cacher::Expirer

#timestamp

Class Method Summary collapse

Methods included from Util::Cacher

extended, included

Methods included from Util::Cacher::Expirer

#dependent_data_expired?, #expire

Class Method Details

.cert_setup(http) ⇒ Object

Use cert information from a Puppet client to set up the http object.



52
53
54
55
56
57
58
59
60
61
# File 'lib/puppet/network/http_pool.rb', line 52

def self.cert_setup(http)
  # Just no-op if we don't have certs.
  return false unless FileTest.exist?(Puppet[:hostcert]) and FileTest.exist?(Puppet[:localcacert])

  http.cert_store = ssl_host.ssl_store
  http.ca_file = Puppet[:localcacert]
  http.cert = ssl_host.certificate.content
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.key = ssl_host.key.content
end

.clear_http_instancesObject

Clear our http cache, closing all connections.



32
33
34
35
36
37
# File 'lib/puppet/network/http_pool.rb', line 32

def self.clear_http_instances
  http_cache.each do |name, connection|
    connection.finish if connection.started?
  end
  Puppet::Util::Cacher.expire
end

.http_instance(host, port, reset = false) ⇒ Object

Retrieve a cached http instance if caching is enabled, else return a new one.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/puppet/network/http_pool.rb', line 65

def self.http_instance(host, port, reset = false)
  # We overwrite the uninitialized @http here with a cached one.
  key = "#{host}:#{port}"

  # Return our cached instance if we've got a cache, as long as we're not
  # resetting the instance.
  if keep_alive?
    return http_cache[key] if ! reset and http_cache[key]

    # Clean up old connections if we have them.
    if http = http_cache[key]
      http_cache.delete(key)
      http.finish if http.started?
    end
  end

  args = [host, port]
  if Puppet[:http_proxy_host] == "none"
    args << nil << nil
  else
    args << Puppet[:http_proxy_host] << Puppet[:http_proxy_port]
  end
  http = Net::HTTP.new(*args)

  # Pop open the http client a little; older versions of Net::HTTP(s) didn't
  # give us a reader for ca_file... Grr...
  class << http; attr_accessor :ca_file; end

  http.use_ssl = true
  # Use configured timeout (#1176)
  http.read_timeout = Puppet[:configtimeout]
  http.open_timeout = Puppet[:configtimeout]

  cert_setup(http)

  http_cache[key] = http if keep_alive?

  http
end

.keep_alive?Boolean



27
28
29
# File 'lib/puppet/network/http_pool.rb', line 27

def self.keep_alive?
  HTTP_KEEP_ALIVE
end

.read_certObject

Make sure we set the driver up when we read the cert in.



40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/network/http_pool.rb', line 40

def self.read_cert
  if val = super # This calls read_cert from the Puppet::SSLCertificates::Support module.
    # Clear out all of our connections, since they previously had no cert and now they
    # should have them.
    clear_http_instances
    return val
  else
    return false
  end
end

.ssl_hostObject

Use the global localhost instance.



18
19
20
# File 'lib/puppet/network/http_pool.rb', line 18

def self.ssl_host
  Puppet::SSL::Host.localhost
end