class Roda::RodaPlugins::Chunked::Body

  1. lib/roda/plugins/chunked.rb
Superclass: Object

Rack response body instance for chunked responses using Transfer-Encoding: chunked.

Methods

Public Class

  1. new

Public Instance

  1. each

Public Class methods

new(scope)

Save the scope of the current request handling.

[show source]
    # File lib/roda/plugins/chunked.rb
171 def initialize(scope)
172   @scope = scope
173 end

Public Instance methods

each()

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.

[show source]
    # File lib/roda/plugins/chunked.rb
180 def each
181   @scope.each_chunk do |chunk|
182     next if !chunk || chunk.empty?
183     yield("%x\r\n" % chunk.bytesize)
184     yield(chunk)
185     yield("\r\n")
186   end
187 ensure
188   yield("0\r\n\r\n")
189 end