This is a specialized handler for Camping applications that has them process the request and then translates the results into something the Mongrel::HttpResponse needs.
# File lib/mongrel/camping.rb, line 40 def initialize(klass) @files = Mongrel::DirHandler.new(nil, false) @guard = Mutex.new @klass = klass end
# File lib/mongrel/camping.rb, line 46 def process(request, response) if response.socket.closed? return end controller = nil @guard.synchronize { controller = @klass.run(request.body, request.params) } sendfile, clength = nil response.status = controller.status controller.headers.each do |k, v| if k =~ /^X-SENDFILE$/ sendfile = v elsif k =~ /^CONTENT-LENGTH$/ clength = v.to_i else [*v].each do |vi| response.header[k] = vi end end end if sendfile request.params[Mongrel::Const::PATH_INFO] = sendfile @files.process(request, response) 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