52: def process(request, response)
53: controller = @klass.run(request.body, request.params)
54: sendfile, clength = nil
55: response.status = controller.status
56: controller.headers.each do |k, v|
57: if k =~ /^X-SENDFILE$/i
58: sendfile = v
59: elsif k =~ /^CONTENT-LENGTH$/i
60: clength = v.to_i
61: else
62: [*v].each do |vi|
63: response.header[k] = vi
64: end
65: end
66: end
67:
68: if sendfile
69: response.send_status(File.size(sendfile))
70: response.send_header
71: response.send_file(sendfile)
72: elsif controller.body.respond_to? :read
73: response.send_status(clength)
74: response.send_header
75: while chunk = controller.body.read(16384)
76: response.write(chunk)
77: end
78: if controller.body.respond_to? :close
79: controller.body.close
80: end
81: else
82: body = controller.body.to_s
83: response.send_status(body.length)
84: response.send_header
85: response.write(body)
86: end
87: end