Class: Reel::StreamResponse

Inherits:
Response show all
Defined in:
lib/reel/stream.rb

Constant Summary collapse

IDENTITY =
'identity'.freeze

Constants inherited from Response

Response::CHUNKED, Response::CONTENT_LENGTH, Response::STATUS_CODES, Response::SYMBOL_TO_STATUS_CODE, Response::TRANSFER_ENCODING

Instance Attribute Summary

Attributes inherited from Response

#body, #headers, #reason, #status, #version

Instance Method Summary collapse

Methods inherited from Response

#chunked?

Constructor Details

#initialize(status, headers, body) ⇒ StreamResponse

Returns a new instance of StreamResponse.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/reel/stream.rb', line 90

def initialize(status, headers, body)
  self.status = status
  @body = body

  case @body
  when EventStream
    # EventSource behaves extremely bad on chunked Transfer-Encoding
    headers[TRANSFER_ENCODING] = IDENTITY
  when ChunkStream
    headers[TRANSFER_ENCODING] = CHUNKED
  when Stream
  else
    raise TypeError, "can't render #{@body.class} as a response body"
  end

  @headers = HTTP::Headers.coerce(headers)
  @version = http_version
end

Instance Method Details

#render(socket) ⇒ Object



109
110
111
# File 'lib/reel/stream.rb', line 109

def render(socket)
  @body.call socket
end