def process(request, response)
controller = @klass.run(request.body, request.params)
sendfile, clength = nil
response.status = controller.status
controller.headers.each do |k, v|
if k =~ /^X-SENDFILE$/i
sendfile = v
elsif k =~ /^CONTENT-LENGTH$/i
clength = v.to_i
else
[*v].each do |vi|
response.header[k] = vi
end
end
end
if sendfile
response.send_status(File.size(sendfile))
response.send_header
response.send_file(sendfile)
elsif controller.body.respond_to? :read
response.send_status(clength)
response.send_header
while chunk = controller.body.read(16384)
response.write(chunk)
end
if controller.body.respond_to? :close
controller.body.close
end
else
body = controller.body.to_s
response.send_status(body.length)
response.send_header
response.write(body)
end
end