Class: Chef::HTTP::StreamHandler
- Inherits:
-
Object
- Object
- Chef::HTTP::StreamHandler
- Defined in:
- lib/chef/http.rb
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.
47 48 49 50 51 52 53 54 |
# File 'lib/chef/http.rb', line 47 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
56 57 58 59 60 61 62 63 |
# File 'lib/chef/http.rb', line 56 def handle_chunk(next_chunk) # stream handlers handle responses so must be applied in reverse order # (same as #apply_stream_complete_middleware or #apply_response_middleware) @stream_handlers.reverse.inject(next_chunk) do |chunk, handler| Chef::Log.trace("Chef::HTTP::StreamHandler calling #{handler.class}#handle_chunk") handler.handle_chunk(chunk) end end |