40: def process(request, response)
41: controller = @klass.run(request.body, request.params)
42: sendfile, clength = nil
43: response.status = controller.status
44: controller.headers.each do |k, v|
45: if k =~ /^X-SENDFILE$/i
46: sendfile = v
47: elsif k =~ /^CONTENT-LENGTH$/i
48: clength = v.to_i
49: else
50: [*v].each do |vi|
51: response.header[k] = vi
52: end
53: end
54: end
55:
56: if sendfile
57: response.send_status(File.size(sendfile))
58: response.send_header
59: response.send_file(sendfile)
60: elsif controller.body.respond_to? :read
61: response.send_status(clength)
62: response.send_header
63: while chunk = controller.body.read(16384)
64: response.write(chunk)
65: end
66: if controller.body.respond_to? :close
67: controller.body.close
68: end
69: else
70: body = controller.body.to_s
71: response.send_status(body.length)
72: response.send_header
73: response.write(body)
74: end
75: end