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