class Roda::RodaPlugins::Chunked::Body
Rack response body instance for chunked responses using Transfer-Encoding: chunked.
Public Class Methods
Source
# File lib/roda/plugins/chunked.rb, line 171 def initialize(scope) @scope = scope end
Save the scope of the current request handling.
Public Instance Methods
Source
# File lib/roda/plugins/chunked.rb, line 180 def each @scope.each_chunk do |chunk| next if !chunk || chunk.empty? yield("%x\r\n" % chunk.bytesize) yield(chunk) yield("\r\n") end ensure yield("0\r\n\r\n") end
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.