1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

* lib/mongrel/camping.rb: borrowing DirHandler and @guard from the RailsHandler.

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@357 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
why 2006-10-05 04:27:44 +00:00
parent 04b3690a2b
commit af7c7e3955

View file

@ -33,13 +33,29 @@ module Mongrel
# the results into something the Mongrel::HttpResponse
# needs.
class CampingHandler < Mongrel::HttpHandler
attr_reader :files
attr_reader :guard
@@file_only_methods = ["GET","HEAD"]
def initialize(klass)
@files = Mongrel::DirHandler.new("/",false)
@guard = Sync.new
@klass = klass
end
def process(request, response)
controller = @klass.run(request.body, request.params)
if response.socket.closed?
return
end
controller = nil
@guard.synchronize(:EX) {
controller = @klass.run(request.body, request.params)
}
sendfile, clength = nil
get_or_head = @@file_only_methods.include? request.params[Mongrel::Const::REQUEST_METHOD]
response.status = controller.status
controller.headers.each do |k, v|
if k =~ /^X-SENDFILE$/i
@ -54,9 +70,8 @@ module Mongrel
end
if sendfile
response.send_status(File.size(sendfile))
response.send_header
response.send_file(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