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)

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?(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)
	elsif body.is_a? Array
		# TODO after dropping 2.3, change to #sum
		length ||= body.inject(0){|sum, chunk| sum + chunk.bytesize}
		return self.new(headers, body, length)
	else
		return self.new(headers, 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)

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(headers, body, length)

def initialize(headers, body, length)
	@length = length
	@body = body
	
	@chunks = nil
end

def inspect

def inspect
	"\#<#{self.class} length=#{@length.inspect} body=#{@body.class}>"
end

def read

def read
	@chunks ||= @body.to_enum(:each)
	
	return @chunks.next
rescue StopIteration
	return nil
end