summaryrefslogtreecommitdiff
path: root/lib/chef/rest.rb
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-10-08 11:04:12 -0700
committerdanielsdeleo <dan@opscode.com>2013-10-08 15:01:48 -0700
commit1ed247de7476eb4e423af97f018a1666fc27f80d (patch)
tree91c17db90e8a6d875c1825df28a48837bc801e7e /lib/chef/rest.rb
parent88439ca8ffbd57e0f7c5133e0846185902014f74 (diff)
downloadchef-1ed247de7476eb4e423af97f018a1666fc27f80d.tar.gz
Express stream handling via middlewares
(This is an intermediate commit for review-ability purposes). Streaming downloads to files is core functionality that needs to go in the base HTTP class, so remove special casing from middlewares for decompressing responses.
Diffstat (limited to 'lib/chef/rest.rb')
-rw-r--r--lib/chef/rest.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index f5a270248b..033153f739 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -194,6 +194,24 @@ class Chef
BasicClient.new(create_url(url))
end
+ class StreamHandler
+ def initialize(middlewares, response)
+ middlewares = middlewares.flatten
+ @stream_handlers = []
+ middlewares.each do |middleware|
+ stream_handler = middleware.stream_response_handler(response)
+ @stream_handlers << stream_handler unless stream_handler.nil?
+ end
+ end
+
+ def handle_chunk(next_chunk)
+ @stream_handlers.inject(next_chunk) do |chunk, handler|
+ handler.handle_chunk(chunk)
+ end
+ end
+
+ end
+
private
def stream_to_tempfile(url, response)
@@ -205,10 +223,10 @@ class Chef
# Stolen from http://www.ruby-forum.com/topic/166423
# Kudos to _why!
- inflater = @decompressor.stream_decompressor_for(response)
+ stream_handler = StreamHandler.new(middlewares, response)
response.read_body do |chunk|
- tf.write(inflater.inflate(chunk))
+ tf.write(stream_handler.handle_chunk(chunk))
end
tf.close
tf