Class: Spikard::StreamingResponse
- Inherits:
-
Object
- Object
- Spikard::StreamingResponse
- Defined in:
- lib/spikard/response.rb,
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.
-
#native_response ⇒ Object
readonly
Returns the value of attribute native_response.
-
#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.
- #to_native_response ⇒ Object
Constructor Details
#initialize(stream, status_code: 200, headers: nil) ⇒ StreamingResponse
Returns a new instance of StreamingResponse.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/spikard/response.rb', line 98 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 rebuild_native! end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
96 97 98 |
# File 'lib/spikard/response.rb', line 96 def headers @headers end |
#native_response ⇒ Object (readonly)
Returns the value of attribute native_response.
96 97 98 |
# File 'lib/spikard/response.rb', line 96 def native_response @native_response end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
96 97 98 |
# File 'lib/spikard/response.rb', line 96 def status_code @status_code end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
96 97 98 |
# File 'lib/spikard/response.rb', line 96 def stream @stream end |
Instance Method Details
#to_native_response ⇒ Object
113 114 115 |
# File 'lib/spikard/response.rb', line 113 def to_native_response @native_response end |