Class: Rack::Chunked::Body

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/rack/chunked.rb

Overview

A body wrapper that emits chunked responses

Constant Summary collapse

TERM =
"\r\n"
TAIL =
"0#{TERM}#{TERM}"

Constants included from Utils

Utils::DEFAULT_SEP, Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN, Utils::HTTP_STATUS_CODES, Utils::Multipart, Utils::PATH_SEPS, Utils::STATUS_WITH_NO_ENTITY_BODY, Utils::SYMBOL_TO_STATUS_CODE

Instance Method Summary collapse

Methods included from Utils

best_q_match, build_nested_query, build_query, byte_ranges, bytesize, clean_path_info, delete_cookie_header!, escape, escape_html, escape_path, normalize_params, params_hash_type?, parse_nested_query, parse_query, q_values, rfc2109, rfc2822, secure_compare, select_best_encoding, set_cookie_header!, status_code, unescape

Constructor Details

#initialize(body) ⇒ Body

Returns a new instance of Body.



17
18
19
# File 'lib/rack/chunked.rb', line 17

def initialize(body)
  @body = body
end

Instance Method Details

#closeObject



33
34
35
# File 'lib/rack/chunked.rb', line 33

def close
  @body.close if @body.respond_to?(:close)
end

#each {|TAIL| ... } ⇒ Object

Yields:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rack/chunked.rb', line 21

def each
  term = TERM
  @body.each do |chunk|
    size = bytesize(chunk)
    next if size == 0

    chunk = chunk.dup.force_encoding(Encoding::BINARY) if chunk.respond_to?(:force_encoding)
    yield [size.to_s(16), term, chunk, term].join
  end
  yield TAIL
end