Class: Spikard::StreamingResponse
- Inherits:
-
Object
- Object
- Spikard::StreamingResponse
- Defined in:
- lib/spikard/streaming_response.rb
Overview
Represents a streaming HTTP response made of chunks produced lazily.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(stream, status_code: 200, headers: nil) ⇒ StreamingResponse
constructor
A new instance of StreamingResponse.
Constructor Details
#initialize(stream, status_code: 200, headers: nil) ⇒ StreamingResponse
Returns a new instance of StreamingResponse.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/spikard/streaming_response.rb', line 8 def initialize(stream, status_code: 200, headers: nil) unless stream.respond_to?(:next) || stream.respond_to?(:each) raise ArgumentError, 'StreamingResponse requires an object responding to #next or #each' end @stream = stream.respond_to?(:to_enum) ? stream.to_enum : stream @status_code = Integer(status_code || 200) header_hash = headers || {} @headers = header_hash.each_with_object({}) do |(key, value), memo| memo[String(key)] = String(value) end end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/spikard/streaming_response.rb', line 6 def headers @headers end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
6 7 8 |
# File 'lib/spikard/streaming_response.rb', line 6 def status_code @status_code end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
6 7 8 |
# File 'lib/spikard/streaming_response.rb', line 6 def stream @stream end |