class Rack::Chunked::Body

A body wrapper that emits chunked responses.

Constants

TAIL
TERM

Public Class Methods

Store the response body to be chunked.

# File lib/rack/chunked.rb, line 30
def initialize(body)
  @body = body
end

Public Instance Methods

Close the response body if the response body supports it.

# File lib/rack/chunked.rb, line 50
def close
  @body.close if @body.respond_to?(:close)
end

For each element yielded by the response body, yield the element in chunked encoding.

# File lib/rack/chunked.rb, line 36
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_trailers(&block)
  yield term
end