class Falcon::Adapters::Output
The Body must respond to each and must only yield String values. The Body itself should not be an instance of String, as this will break in Ruby 1.9. 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)
def self.wrap(status, headers, body) # In no circumstance do we want this header propagating out: if content_length = headers.delete(CONTENT_LENGTH) # We don't really trust the user to provide the right length to the transport. content_length = Integer(content_length) end if body.is_a?(Async::HTTP::Body::Readable) return body elsif status == 200 and body.respond_to?(:to_path) # Don't mangle partial responsese (206) return Async::HTTP::Body::File.open(body.to_path) else return self.new(headers, body, content_length) end end
def close(error = nil)
def close(error = nil) if @body and @body.respond_to?(:close) @body.close @body = nil end @chunks = nil super end
def empty?
def empty? @length == 0 or (@body.respond_to?(:empty?) and @body.empty?) end
def initialize(headers, body, length)
def initialize(headers, body, length) @length = length @body = body # An enumerator over the rack response body: @chunks = body.to_enum(:each) end
def inspect
def inspect "\#<#{self.class} length=#{@length.inspect} body=#{@body.class}>" end
def read
def read if @chunks return @chunks.next end rescue StopIteration nil end