class Protocol::Rack::Body::Enumerable
The ‘rack` body must respond to `each` and must only yield `String` values. If the body responds to `close`, it will be called after iteration.
Wraps the rack response body.
def self.wrap(body, length = nil)
Wraps an array into a buffered body.
def self.wrap(body, length = nil) if body.is_a?(Array) length ||= body.sum(&:bytesize) return self.new(body, length) else return self.new(body, length) end end
def call(stream)
def call(stream) @body.call(stream) ensure self.close($!) end
def close(error = nil)
def close(error = nil) if @body and @body.respond_to?(:close) @body.close end @body = nil @chunks = nil super end
def each(&block)
@yields {|chunk| ...}
Enumerate the response body.
def each(&block) @body.each(&block) ensure self.close($!) end
def empty?
def empty? @length == 0 or (@body.respond_to?(:empty?) and @body.empty?) end
def initialize(body, length)
@parameter body [Object] The rack response body.
Initialize the output wrapper.
def initialize(body, length) @length = length @body = body @chunks = nil end
def inspect
def inspect "\#<#{self.class} length=#{@length.inspect} body=#{@body.class}>" end
def read
Read the next chunk from the response body.
def read @chunks ||= @body.to_enum(:each) return @chunks.next rescue StopIteration return nil end
def ready?
def ready? body.is_a?(Array) or body.respond_to?(:to_ary) end
def stream?
def stream? !@body.respond_to?(:each) end