From 18af4dbcc14eb7765bc021f94a444cc394864c26 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 12 Apr 2009 23:41:30 -0700 Subject: old_rails: try harder to ensure valid responses Hopefully the world will just move to Rack faster so we have less things to worry about. --- lib/unicorn/app/old_rails.rb | 12 +++++++++--- lib/unicorn/cgi_wrapper.rb | 6 ++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/unicorn/app/old_rails.rb b/lib/unicorn/app/old_rails.rb index bb9577a..4b74666 100644 --- a/lib/unicorn/app/old_rails.rb +++ b/lib/unicorn/app/old_rails.rb @@ -13,9 +13,15 @@ class Unicorn::App::OldRails def call(env) cgi = Unicorn::CGIWrapper.new(env) - Dispatcher.dispatch(cgi, - ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, - cgi.body) + begin + Dispatcher.dispatch(cgi, + ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, + cgi.body) + rescue Object => e + err = env['rack.errors'] + out.write("#{e} #{e.message}\n") + e.backtrace.each { |line| out.write("#{line}\n") } + end cgi.out # finalize the response cgi.rack_response end diff --git a/lib/unicorn/cgi_wrapper.rb b/lib/unicorn/cgi_wrapper.rb index 48771fd..bc622ea 100644 --- a/lib/unicorn/cgi_wrapper.rb +++ b/lib/unicorn/cgi_wrapper.rb @@ -71,11 +71,9 @@ class Unicorn::CGIWrapper < ::CGI # Capitalized "Status:", with human-readable status code (e.g. "200 OK") parseable_status = @head.delete(Status) - unless @status - @status ||= parseable_status.split(/ /)[0].to_i rescue 404 - end + @status ||= parseable_status.split(/ /)[0].to_i rescue 500 - [ @status, @head, [ @body.string ] ] + [ @status || 500, @head, [ @body.string ] ] end # The header is typically called to send back the header. In our case we -- cgit v1.2.3-24-ge0c7