class Falcon::Adapters::Output
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. If the body is replaced by a middleware after action, the original body must be closed first, if it responds to `close`. If the body responds to `to_path`, it must return a String identifying the location of a file whose contents are identical to that produced by calling `each`; this may be used by the server as an alternative, possibly more efficient way to transport the response. The body commonly is an `Array` of strings, the application instance itself, or a `File`-like object.
Wraps the rack response body.
def self.wrap(status, headers, body)
@parameter headers [Protocol::HTTP::Headers] The response headers.
@parameter status [Integer] The response status.
Wraps an array into a buffered body.
def self.wrap(status, headers, body) # In no circumstance do we want this header propagating out: if length = headers.delete(CONTENT_LENGTH) # We don't really trust the user to provide the right length to the transport. length = Integer(length) end if body.is_a?(::Protocol::HTTP::Body::Readable) return body elsif status == 200 and body.respond_to?(:to_path) # Don't mangle partial responsese (206) return ::Protocol::HTTP::Body::File.open(body.to_path) elsif body.is_a?(Array) length ||= body.sum(&:bytesize) return self.new(body, length) else return self.new(body, length) end 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? true end