summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2016-02-29 15:34:15 -0800
committerNoah Kantrowitz <noah@coderanger.net>2016-02-29 15:34:15 -0800
commitb4b8120191de45f5f8f8611dde244fde714b1004 (patch)
tree698b8c7b85afaafede57ebcfbdf1a5f7a3e78e51
parentc824aa564fa1a193d76b47fa430742c0a756eaa2 (diff)
downloadchef-b4b8120191de45f5f8f8611dde244fde714b1004.tar.gz
Split the negative check to its own log message.
-rw-r--r--lib/chef/http/validate_content_length.rb7
-rw-r--r--spec/unit/http/validate_content_length_spec.rb2
2 files changed, 7 insertions, 2 deletions
diff --git a/lib/chef/http/validate_content_length.rb b/lib/chef/http/validate_content_length.rb
index 17219a7c89..81d3b0fb74 100644
--- a/lib/chef/http/validate_content_length.rb
+++ b/lib/chef/http/validate_content_length.rb
@@ -86,11 +86,16 @@ class Chef
transfer_encoding = http_response["transfer-encoding"]
content_encoding = http_response["content-encoding"]
- if content_length.nil? || content_length < 0
+ if content_length.nil?
Chef::Log.debug "HTTP server did not include a Content-Length header in response, cannot identify truncated downloads."
return true
end
+ if content_length < 0
+ Chef::Log.debug "HTTP server responded with a negative Content-Length header (#{content_length}), cannot identify truncated downloads."
+ return true
+ end
+
# if Transfer-Encoding is set the RFC states that we must ignore the Content-Length field
# CHEF-5041: some proxies uncompress gzip content, leave the incorrect content-length, but set the transfer-encoding field
unless transfer_encoding.nil?
diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb
index 7fedb66b11..ddcdaea91f 100644
--- a/spec/unit/http/validate_content_length_spec.rb
+++ b/spec/unit/http/validate_content_length_spec.rb
@@ -128,7 +128,7 @@ describe Chef::HTTP::ValidateContentLength do
it "should skip validation and log for debug" do
run_content_length_validation
- expect(debug_output).to include("HTTP server did not include a Content-Length header in response")
+ expect(debug_output).to include("HTTP server responded with a negative Content-Length header (-1), cannot identify truncated downloads.")
end
end
end