Class: ActionController::Streaming::Body
- Inherits:
-
Object
- Object
- ActionController::Streaming::Body
- Defined in:
- lib/action_controller/metal/streaming.rb
Overview
:nodoc:
Constant Summary collapse
- TERM =
"\r\n"
- TAIL =
"0#{TERM}"
Instance Method Summary collapse
-
#close ⇒ Object
Close the response body if the response body supports it.
-
#each {|TAIL| ... } ⇒ Object
For each element yielded by the response body, yield the element in chunked encoding.
-
#initialize(body) ⇒ Body
constructor
Store the response body to be chunked.
Constructor Details
#initialize(body) ⇒ Body
Store the response body to be chunked.
214 215 216 |
# File 'lib/action_controller/metal/streaming.rb', line 214 def initialize(body) @body = body end |
Instance Method Details
#close ⇒ Object
Close the response body if the response body supports it.
233 234 235 |
# File 'lib/action_controller/metal/streaming.rb', line 233 def close @body.close if @body.respond_to?(:close) end |
#each {|TAIL| ... } ⇒ Object
For each element yielded by the response body, yield the element in chunked encoding.
220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/action_controller/metal/streaming.rb', line 220 def each(&block) term = TERM @body.each do |chunk| size = chunk.bytesize next if size == 0 yield [size.to_s(16), term, chunk.b, term].join end yield TAIL yield term end |