mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Fix for that same content-length bug, but now fixed by gutting CGI to use HttpResponse right.
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@38 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
parent
a18fa951bb
commit
fd11f72b2f
2 changed files with 43 additions and 29 deletions
|
@ -9,11 +9,11 @@ class CGIFixed < ::CGI
|
||||||
public :env_table
|
public :env_table
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
|
|
||||||
def initialize(params, data, out, *args)
|
def initialize(request, response, *args)
|
||||||
@env_table = params
|
@request = request
|
||||||
|
@response = response
|
||||||
@args = *args
|
@args = *args
|
||||||
@input = StringIO.new(data)
|
@input = StringIO.new(request.body)
|
||||||
@out = out
|
|
||||||
@options = {}
|
@options = {}
|
||||||
super(*args)
|
super(*args)
|
||||||
end
|
end
|
||||||
|
@ -21,15 +21,37 @@ class CGIFixed < ::CGI
|
||||||
def header(options = "text/html")
|
def header(options = "text/html")
|
||||||
if options.class == Hash
|
if options.class == Hash
|
||||||
# passing in a header so need to keep the status around and other options
|
# passing in a header so need to keep the status around and other options
|
||||||
@options = options
|
@options = @options.merge(options)
|
||||||
|
else
|
||||||
|
@options["Content-Type"] = options
|
||||||
end
|
end
|
||||||
|
|
||||||
super(options)
|
# doing this fakes out the cgi library to think the headers are empty
|
||||||
|
# we then do the real headers in the out function call later
|
||||||
|
""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def out(options = "text/html")
|
||||||
|
header(options)
|
||||||
|
@response.start status do |head, out|
|
||||||
|
@options.each {|k,v| head[k.capitalize] = v}
|
||||||
|
out.write(yield || "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# computes the status once, but lazily so that people who call header twice
|
||||||
|
# don't get penalized
|
||||||
def status
|
def status
|
||||||
s = @options["Status"] || @options["status"]
|
if not @status
|
||||||
s[0 .. s.index(' ')] || "200"
|
@status = @options["Status"] || @options["status"]
|
||||||
|
|
||||||
|
if @status
|
||||||
|
@status[0 ... @status.index(' ')] || "200"
|
||||||
|
else
|
||||||
|
@status = "200"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def args
|
def args
|
||||||
|
@ -37,15 +59,7 @@ class CGIFixed < ::CGI
|
||||||
end
|
end
|
||||||
|
|
||||||
def env_table
|
def env_table
|
||||||
@env_table
|
@request.params
|
||||||
end
|
|
||||||
|
|
||||||
def stdinput
|
|
||||||
@input
|
|
||||||
end
|
|
||||||
|
|
||||||
def stdoutput
|
|
||||||
@out
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,22 +81,22 @@ class RailsHandler < Mongrel::HttpHandler
|
||||||
if @files.can_serve(request.params["PATH_INFO"])
|
if @files.can_serve(request.params["PATH_INFO"])
|
||||||
@files.process(request,response)
|
@files.process(request,response)
|
||||||
else
|
else
|
||||||
cgi = CGIFixed.new(request.params, request.body, response.socket)
|
cgi = CGIFixed.new(request, response)
|
||||||
begin
|
|
||||||
|
|
||||||
|
begin
|
||||||
@guard.synchronize do
|
@guard.synchronize do
|
||||||
# Rails is not thread safe so must be run entirely within synchronize
|
# Rails is not thread safe so must be run entirely within synchronize
|
||||||
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
|
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
|
||||||
end
|
end
|
||||||
|
|
||||||
response.status = cgi.status
|
# This finalizes the output using the proper HttpResponse way
|
||||||
response.send_status
|
cgi.out {""}
|
||||||
response.send_body
|
|
||||||
rescue Object => rails_error
|
rescue Object => rails_error
|
||||||
STDERR.puts "calling Dispatcher.dispatch #{rails_error}"
|
STDERR.puts "calling Dispatcher.dispatch #{rails_error}"
|
||||||
STDERR.puts rails_error.backtrace.join("\n")
|
STDERR.puts rails_error.backtrace.join("\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ module Mongrel
|
||||||
SERVER_SOFTWARE='SERVER_SOFTWARE'
|
SERVER_SOFTWARE='SERVER_SOFTWARE'
|
||||||
|
|
||||||
# Current Mongrel version (used for SERVER_SOFTWARE and other response headers).
|
# Current Mongrel version (used for SERVER_SOFTWARE and other response headers).
|
||||||
MONGREL_VERSION='Mongrel 0.2.2'
|
MONGREL_VERSION='Mongrel 0.3.4'
|
||||||
|
|
||||||
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
|
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
|
||||||
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND"
|
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND"
|
||||||
|
@ -243,7 +243,7 @@ module Mongrel
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_status
|
def send_status
|
||||||
@socket.write("HTTP/1.1 #{@status.to_i} #{HTTP_STATUS_CODES[@status.to_i]}\r\nContent-Length:#{body.length}\r\nConnection: close\r\n")
|
@socket.write("HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status]}\r\nContent-Length: #{@body.length}\r\nConnection: close\r\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_header
|
def send_header
|
||||||
|
|
Loading…
Add table
Reference in a new issue