summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalim Alam <salam@chef.io>2016-03-17 14:04:53 -0700
committerSalim Alam <salam@chef.io>2016-03-17 14:04:53 -0700
commitf4deae20c7ae3b270d7b476a270100576977f700 (patch)
tree68140351d78fc7c6704c9c3a77bbc6f718b67860
parentf07cfc03115bc4680afb4d874538e1c6bb6551bb (diff)
downloadchef-cd/no_proxy.tar.gz
Override no_proxy with internal matchercd/no_proxy
-rw-r--r--chef-config/lib/chef-config/config.rb10
-rw-r--r--chef.gemspec1
-rw-r--r--lib/chef/http/basic_client.rb7
3 files changed, 15 insertions, 3 deletions
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index 623e8c9d87..c75139e49f 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -27,6 +27,7 @@ require "chef-config/windows"
require "chef-config/path_helper"
require "mixlib/shellout"
require "uri"
+require "fuzzyurl"
require "openssl"
module ChefConfig
@@ -855,8 +856,13 @@ module ChefConfig
end
excludes = ENV["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}") }
+ return proxy unless excludes.any? { |exclude| fuzzy_hostname_match?(exclude, host) }
+ end
+
+ def self.fuzzy_hostname_match?(match, hostname)
+ # Do greedy matching by adding wildcard if it is not specified
+ match = "*" + match if !match.start_with?("*")
+ Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
end
# Chef requires an English-language UTF-8 locale to function properly. We attempt
diff --git a/chef.gemspec b/chef.gemspec
index c55b2423ed..159f803c91 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
s.add_dependency "diff-lcs", "~> 1.2", ">= 1.2.4"
s.add_dependency "chef-zero", "~> 4.5"
+ s.add_dependency "fuzzyurl", '~> 0.8.0'
s.add_dependency "plist", "~> 3.1.0"
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index b6ae5d9a6f..796550a516 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -100,7 +100,12 @@ class Chef
end
def build_http_client
- http_client = http_client_builder.new(host, port)
+ # Note: the last nil in the new below forces Net::HTTP to ignore the
+ # no_proxy environment variable. This is a workaround for limitations
+ # in Net::HTTP use of the no_proxy environment variable. We internally
+ # match no_proxy with a fuzzy matcher, rather than letting Net::HTTP
+ # do it.
+ http_client = http_client_builder.new(host, port, nil)
if url.scheme == HTTPS
configure_ssl(http_client)