summaryrefslogtreecommitdiff
path: root/lib/chef/http
diff options
context:
space:
mode:
authorNathan L Smith <smith@chef.io>2015-12-30 11:10:51 -0600
committerChris Doherty <cdoherty@chef.io>2016-03-17 14:49:49 -0700
commitfda49f6f8133fbb6f389f1def8e0aad4856614b7 (patch)
treecc3a4fb54f58932e1be9f73ab290ebf728fa18ab /lib/chef/http
parent17ca25869fd9e0ce0a4ec013a5dc39549ecaa6f7 (diff)
downloadchef-fda49f6f8133fbb6f389f1def8e0aad4856614b7.tar.gz
Make handling of proxies more consistent
* Always use `*_proxy` environment variables. * Make a `ChefConfig::Config.proxy_uri` method that gets used by `Chef::Provider::RemoteFile::FTP` and `Chef::HTTP::BasicClient`. * Remove `env` method from `Chef::HTTP::BasicClient` (using `stub_const("ENV", ...)` in specs instead.) * Remove `http_proxy_user` and `http_proxy_pass` methods from `Chef::HTTP::BasicClient` (replaced by functionality in `ChefConfig`.)
Diffstat (limited to 'lib/chef/http')
-rw-r--r--lib/chef/http/basic_client.rb44
1 files changed, 5 insertions, 39 deletions
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index 58ae496418..b6ae5d9a6f 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -95,26 +95,8 @@ class Chef
raise
end
- #adapted from buildr/lib/buildr/core/transports.rb
def proxy_uri
- proxy = Chef::Config["#{url.scheme}_proxy"] ||
- env["#{url.scheme.upcase}_PROXY"] || env["#{url.scheme}_proxy"]
-
- # Check if the proxy string contains a scheme. If not, add the url's scheme to the
- # proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy
- # here since we are really just trying to get the string built correctly.
- if String === proxy && !proxy.strip.empty?
- if proxy =~ /^.*:\/\//
- proxy = URI.parse(proxy.strip)
- else
- proxy = URI.parse("#{url.scheme}://#{proxy.strip}")
- end
- end
-
- no_proxy = Chef::Config[:no_proxy] || env["NO_PROXY"] || env["no_proxy"]
- excludes = no_proxy.to_s.split(/\s*,\s*/).compact
- excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
- return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") }
+ @proxy_uri ||= ChefConfig::Config.proxy_uri(url.scheme, host, port)
end
def build_http_client
@@ -133,32 +115,16 @@ class Chef
Chef::Config
end
- def env
- ENV
- end
-
def http_client_builder
- http_proxy = proxy_uri
- if http_proxy.nil?
+ if proxy_uri.nil?
Net::HTTP
else
- Chef::Log.debug("Using #{http_proxy.host}:#{http_proxy.port} for proxy")
- user = http_proxy_user(http_proxy)
- pass = http_proxy_pass(http_proxy)
- Net::HTTP.Proxy(http_proxy.host, http_proxy.port, user, pass)
+ Chef::Log.debug("Using #{proxy_uri.host}:#{proxy_uri.port} for proxy")
+ Net::HTTP.Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user,
+ proxy_uri.password)
end
end
- def http_proxy_user(http_proxy)
- http_proxy.user || Chef::Config["#{url.scheme}_proxy_user"] ||
- env["#{url.scheme.upcase}_PROXY_USER"] || env["#{url.scheme}_proxy_user"]
- end
-
- def http_proxy_pass(http_proxy)
- http_proxy.password || Chef::Config["#{url.scheme}_proxy_pass"] ||
- env["#{url.scheme.upcase}_PROXY_PASS"] || env["#{url.scheme}_proxy_pass"]
- end
-
def configure_ssl(http_client)
http_client.use_ssl = true
ssl_policy.apply_to(http_client)