summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlaas Jan Wierenga <k.j.wierenga@gmail.com>2014-06-05 12:10:58 +0200
committerKlaas Jan Wierenga <k.j.wierenga@gmail.com>2014-06-07 23:06:03 +0200
commitfd407cddb17003ffcf7318a2f48ebce8084f9074 (patch)
tree276974ad4f790a4774a163096e439cb6120eb559
parentb3b7ec83c9d507d734ff7375fff4809dab6a960a (diff)
downloadchef-fd407cddb17003ffcf7318a2f48ebce8084f9074.tar.gz
Only pass on port in Host header when it is different from default port
for URI scheme (80 or 443). Fixes CHEF-5355.
-rw-r--r--lib/chef/http/http_request.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb
index 90b805e73f..7582f4458f 100644
--- a/lib/chef/http/http_request.rb
+++ b/lib/chef/http/http_request.rb
@@ -60,6 +60,8 @@ class Chef
HOST_LOWER = "host".freeze
+ URI_SCHEME_DEFAULT_PORT = { 'http' => 80, 'https' => 443 }.freeze
+
def self.user_agent=(ua)
@user_agent = ua
end
@@ -138,7 +140,13 @@ class Chef
# No response compression unless we asked for it explicitly:
@headers[HTTPRequest::ACCEPT_ENCODING] ||= "identity"
@headers['X-Chef-Version'] = ::Chef::VERSION
- @headers['Host'] = "#{uri_safe_host}:#{port}" unless @headers.keys.any? {|k| k.downcase.to_s == HOST_LOWER }
+
+ # Only include port in Host header when it is not the default port
+ # for the url scheme (80;443) - Fixes CHEF-5355
+ host_header = uri_safe_host.dup
+ host_header << ":#{port}" unless URI_SCHEME_DEFAULT_PORT[@url.scheme] == port.to_i
+ @headers['Host'] = host_header unless @headers.keys.any? {|k| k.downcase.to_s == HOST_LOWER }
+
@headers
end