module Puppet::HTTP::HttpProxy

Public Class Methods

http_proxy_env() click to toggle source
   # File lib/puppet/http/proxy.rb
18 def self.http_proxy_env
19   # Returns a URI object if proxy is set, or nil
20   proxy_env = ENV["http_proxy"] || ENV["HTTP_PROXY"]
21   begin
22     return URI.parse(proxy_env) if proxy_env
23   rescue URI::InvalidURIError
24     return nil
25   end
26   return nil
27 end
http_proxy_host() click to toggle source
   # File lib/puppet/http/proxy.rb
73 def self.http_proxy_host
74   env = self.http_proxy_env
75 
76   if env and env.host
77     return env.host
78   end
79 
80   if Puppet.settings[:http_proxy_host] == 'none'
81     return nil
82   end
83 
84   return Puppet.settings[:http_proxy_host]
85 end
http_proxy_password() click to toggle source
    # File lib/puppet/http/proxy.rb
111 def self.http_proxy_password
112   env = self.http_proxy_env
113 
114   if env and env.password
115     return env.password
116   end
117 
118   if Puppet.settings[:http_proxy_user] == 'none' or Puppet.settings[:http_proxy_password] == 'none'
119     return nil
120   end
121 
122   return Puppet.settings[:http_proxy_password]
123 end
http_proxy_port() click to toggle source
   # File lib/puppet/http/proxy.rb
87 def self.http_proxy_port
88   env = self.http_proxy_env
89 
90   if env and env.port
91     return env.port
92   end
93 
94   return Puppet.settings[:http_proxy_port]
95 end
http_proxy_user() click to toggle source
    # File lib/puppet/http/proxy.rb
 97 def self.http_proxy_user
 98   env = self.http_proxy_env
 99 
100   if env and env.user
101     return env.user
102   end
103 
104   if Puppet.settings[:http_proxy_user] == 'none'
105     return nil
106   end
107 
108   return Puppet.settings[:http_proxy_user]
109 end
no_proxy() click to toggle source
    # File lib/puppet/http/proxy.rb
125 def self.no_proxy
126   no_proxy_env = ENV["no_proxy"] || ENV["NO_PROXY"]
127 
128   if no_proxy_env
129     return no_proxy_env
130   end
131 
132   if Puppet.settings[:no_proxy] == 'none'
133     return nil
134   end
135 
136   return Puppet.settings[:no_proxy]
137 end
no_proxy?(dest) click to toggle source

The documentation around the format of the no_proxy variable seems inconsistent. Some suggests the use of the * as a way of matching any hosts under a domain, e.g.:

*.example.com

Other documentation suggests that just a leading '.' indicates a domain level exclusion, e.g.:

.example.com

We'll accommodate both here.

   # File lib/puppet/http/proxy.rb
37 def self.no_proxy?(dest)
38   no_proxy = self.no_proxy
39   unless no_proxy
40     return false
41   end
42 
43   unless dest.is_a? URI
44     begin
45       dest = URI.parse(dest)
46     rescue URI::InvalidURIError
47       return false
48     end
49   end
50 
51   no_proxy.split(/\s*,\s*/).each do |d|
52     host, port = d.split(':')
53     host = Regexp.escape(host).gsub('\*', '.*')
54 
55     #If this no_proxy entry specifies a port, we want to match it against
56     #the destination port.  Otherwise just match hosts.
57     if port
58       no_proxy_regex  = %r(#{host}:#{port}$)
59       dest_string     = "#{dest.host}:#{dest.port}"
60     else
61       no_proxy_regex  = %r(#{host}$)
62       dest_string     = "#{dest.host}"
63     end
64 
65     if no_proxy_regex.match(dest_string)
66       return true
67     end
68   end
69 
70   return false
71 end
proxy(uri) click to toggle source
   # File lib/puppet/http/proxy.rb
 6 def self.proxy(uri)
 7   if http_proxy_host && !no_proxy?(uri)
 8     Net::HTTP.new(uri.host, uri.port, self.http_proxy_host, self.http_proxy_port, self.http_proxy_user, self.http_proxy_password)
 9   else
10     http = Net::HTTP.new(uri.host, uri.port, nil, nil, nil, nil)
11     # Net::HTTP defaults the proxy port even though we said not to
12     # use one. Set it to nil so caller is not surprised
13     http.proxy_port = nil
14     http
15   end
16 end