20. Response body can be any
object that respond_to?(:each)
file = File.new('myfile.xml')
[200, { 'Content-Type' => 'application/xml' }, file]
21. class StreamingFile
def initialize(file)
@file = file
end
def length
File.size(@file)
end
def last_modified
File.mtime(@file).rfc822
end
def each
File.open(@file, "rb") do |file|
while part = file.read(8192)
yield part
end
File.delete(@file)
end
end