Class: Chef::HTTP::StreamHandler

Inherits:
Object
  • Object
show all
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

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