Class: Roda::RodaPlugins::Chunked::Body
- Inherits:
-
Object
- Object
- Roda::RodaPlugins::Chunked::Body
- Defined in:
- lib/roda/plugins/chunked.rb
Overview
Rack response body instance for chunked responses
Constant Summary collapse
- CHUNK_SIZE =
"%x\r\n".freeze
- CRLF =
"\r\n".freeze
- FINISH =
"0\r\n\r\n".freeze
Instance Method Summary collapse
-
#each ⇒ Object
For each response chunk yielded by the scope, yield it it to the caller in chunked format, starting with the size of the request in ASCII hex format, then the chunk.
-
#initialize(scope) ⇒ Body
constructor
Save the scope of the current request handling.
Constructor Details
#initialize(scope) ⇒ Body
Save the scope of the current request handling.
176 177 178 |
# File 'lib/roda/plugins/chunked.rb', line 176 def initialize(scope) @scope = scope end |
Instance Method Details
#each ⇒ Object
For each response chunk yielded by the scope, yield it it to the caller in chunked format, starting with the size of the request in ASCII hex format, then the chunk. After all chunks have been yielded, yield a 0 sized chunk to finish the response.
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/roda/plugins/chunked.rb', line 185 def each @scope.each_chunk do |chunk| next if !chunk || chunk.empty? yield(CHUNK_SIZE % chunk.bytesize) yield(chunk) yield(CRLF) end ensure yield(FINISH) end |