class Chef::HTTP::StreamHandler

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.

Public Class Methods

new(middlewares, response) click to toggle source
# 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

Public Instance Methods

handle_chunk(next_chunk) click to toggle source
# 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