Class: Chef::HTTP::StreamHandler
Overview
Class for applying middleware behaviors to streaming responses. Collects stream handlers (if any) from each middleware. When #handle_chunk is called, the chunk gets passed to all handlers in turn for processing.
Instance Method Summary collapse
- #handle_chunk(next_chunk) ⇒ Object
-
#initialize(middlewares, response) ⇒ StreamHandler
constructor
A new instance of StreamHandler.
Constructor Details
#initialize(middlewares, response) ⇒ StreamHandler
Returns a new instance of StreamHandler.
43 44 45 46 47 48 49 50 |
# File 'lib/chef/http.rb', line 43 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 |
Instance Method Details
#handle_chunk(next_chunk) ⇒ Object
52 53 54 55 56 |
# File 'lib/chef/http.rb', line 52 def handle_chunk(next_chunk) @stream_handlers.inject(next_chunk) do |chunk, handler| handler.handle_chunk(chunk) end end |