summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-01-20 16:07:21 -0800
committerClaire McQuin <claire@getchef.com>2014-01-23 16:57:29 -0800
commit5a36e2997b331e29ade28022e6c6a98ea5d08f35 (patch)
treef55a30164c0e0b1ef6f3db0c18532866d18ed701 /lib
parent3fac3c63633ac7c9ee18cfd49da46642caa8f796 (diff)
downloadchef-5a36e2997b331e29ade28022e6c6a98ea5d08f35.tar.gz
add counting content-length for streaming requests
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/http/validate_response.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/chef/http/validate_response.rb b/lib/chef/http/validate_response.rb
index b38673ef3a..ccf5bdb454 100644
--- a/lib/chef/http/validate_response.rb
+++ b/lib/chef/http/validate_response.rb
@@ -26,6 +26,18 @@ class Chef
# Middleware that takes an HTTP response, parses it as JSON if possible.
class ValidateResponse
+ class ContentLengthCounter
+ attr_accessor :content_length
+
+ def initialize
+ @content_length = 0
+ end
+
+ def handle_chunk(chunk)
+ @content_length += chunk.bytesize
+ end
+ end
+
def initialize(opts={})
end
@@ -40,7 +52,7 @@ class Chef
end
content_length = http_response['content-length'].is_a?(Array) ? http_response['content-length'].first.to_i : http_response['content-length'].to_i
Chef::Log.debug "Content-Length header = #{content_length}"
- response_length = http_response.body.length # FIXME: use byte length to deal with encoding?
+ response_length = http_response.body.bytesize
Chef::Log.debug "Response body length = #{response_length}"
if response_length != content_length
raise "Response body length #{response_length} does not match HTTP Content-Length header #{content_length}" #FIXME: real exception
@@ -49,7 +61,7 @@ class Chef
end
def stream_response_handler(response)
- nil
+ @content_length_counter = ContentLengthCounter.new
end
end