From 18e93c034db0c08bcc5b5f7a72a8fb6e909c009c Mon Sep 17 00:00:00 2001 From: evanweaver Date: Mon, 24 Mar 2008 03:48:10 +0000 Subject: Backport Eric's changes to the http parser from trunk (Eric Wong). Apply fix for Ragel 6 (Eric Wong, Ry Dahl). Two tests fail with the new parser (1 failed with the old parser). Needs investigation. Close #12 (mongrel_rails send_signal leaves a filehandle open until gc). Close #14 (mongrel_rails command line option --num-procs does not change the max number of procs). Close #15 (mongrel squashes helpful exception in register method). Close #16, XXX needs audit! (CGIWrapper "options" attr_reader has no corresponding @options variable). Close #20 (Mongrel doesn't erase temporary files during it's operation on windows). Close #19, XXX needs audit! (HttpResponse#reset does not properly reset HeaderOut). Close #22 (gem_plugin should load gems from Gem.path not Gem.dir). Close #23 (mongrel_cluster's mongrel_rails configuration option isn't fully respected). If I had git, being offline wouldn't have resulted in one massive commit. git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/branches/stable_1-2@995 19e92222-5c0b-0410-8929-a290d50e31e9 --- lib/mongrel.rb | 13 +++++++++---- lib/mongrel/cgi.rb | 4 ++-- lib/mongrel/http_request.rb | 2 +- lib/mongrel/http_response.rb | 5 ++++- 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/mongrel.rb b/lib/mongrel.rb index d99c56d..1963322 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -200,7 +200,7 @@ module Mongrel STDERR.puts "#{Time.now}: Client error: #{e.inspect}" STDERR.puts e.backtrace.join("\n") end - request.body.delete if request and request.body.class == Tempfile + request.body.close! if request and request.body.class == Tempfile end end @@ -320,10 +320,15 @@ module Mongrel def register(uri, handler, in_front=false) begin @classifier.register(uri, [handler]) - rescue URIClassifier::RegistrationError + rescue URIClassifier::RegistrationError => e handlers = @classifier.resolve(uri)[2] - method_name = in_front ? 'unshift' : 'push' - handlers.send(method_name, handler) + if handlers + # Already registered + method_name = in_front ? 'unshift' : 'push' + handlers.send(method_name, handler) + else + raise + end end handler.listener = self end diff --git a/lib/mongrel/cgi.rb b/lib/mongrel/cgi.rb index 4173bde..3957611 100644 --- a/lib/mongrel/cgi.rb +++ b/lib/mongrel/cgi.rb @@ -26,7 +26,7 @@ module Mongrel # Refer to DirHandler#can_serve for more information on this. class CGIWrapper < ::CGI public :env_table - attr_reader :options + attr_reader :head attr_accessor :handler # Set this to false if you want calls to CGIWrapper.out to not actually send # the response until you force it. @@ -105,7 +105,7 @@ module Mongrel when Hash cookie.each_value {|c| to['Set-Cookie'] = c.to_s} else - to['Set-Cookie'] = options['cookie'].to_s + to['Set-Cookie'] = head['cookie'].to_s end @head.delete('cookie') diff --git a/lib/mongrel/http_request.rb b/lib/mongrel/http_request.rb index 82ffe42..c8d4ce4 100644 --- a/lib/mongrel/http_request.rb +++ b/lib/mongrel/http_request.rb @@ -93,7 +93,7 @@ module Mongrel STDERR.puts e.backtrace.join("\n") # any errors means we should delete the file, including if the file is dumped @socket.close rescue nil - @body.delete if @body.class == Tempfile + @body.close! if @body.class == Tempfile @body = nil # signals that there was a problem end end diff --git a/lib/mongrel/http_response.rb b/lib/mongrel/http_response.rb index 32e433e..3076712 100644 --- a/lib/mongrel/http_response.rb +++ b/lib/mongrel/http_response.rb @@ -75,7 +75,10 @@ module Mongrel elsif @header_sent raise "You have already sent the request headers." else - @header.out.truncate(0) + # XXX Dubious ( http://mongrel.rubyforge.org/ticket/19 ) + @header.out.close + @header = HeaderOut.new(StringIO.new) + @body.close @body = StringIO.new end -- cgit v1.2.3-24-ge0c7