about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-04-01 01:19:27 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-01 01:40:22 -0700
commitb2569b344d61a7d26033aeb6198d23f99d2e7f3e (patch)
tree8a21fce2d458d3b9b5c9bbb08325719c53821f0b
parentad6a90ea1e0c1bd3959944f46672d754546dfb33 (diff)
downloadunicorn-b2569b344d61a7d26033aeb6198d23f99d2e7f3e.tar.gz
The default status was 404 in Mongrel and this is needed to work
with older versions of Rails.  Additionally parse the "Status:"
header if it ever got set and the actual "status" code passed
to CGI::headers was not set.
-rw-r--r--lib/unicorn/cgi_wrapper.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/unicorn/cgi_wrapper.rb b/lib/unicorn/cgi_wrapper.rb
index 7959945..48771fd 100644
--- a/lib/unicorn/cgi_wrapper.rb
+++ b/lib/unicorn/cgi_wrapper.rb
@@ -38,6 +38,7 @@ class Unicorn::CGIWrapper < ::CGI
 
   # this maps CGI header names to HTTP header names
   HEADER_MAP = {
+    'status' => Status,
     'type' => CONTENT_TYPE,
     'server' => 'Server'.freeze,
     'language' => 'Content-Language'.freeze,
@@ -53,7 +54,7 @@ class Unicorn::CGIWrapper < ::CGI
   # Mongrel...
   def initialize(rack_env, *args)
     @env_table = rack_env
-    @status = 200
+    @status = nil
     @head = {}
     @headv = Hash.new { |hash,key| hash[key] = [] }
     @body = StringIO.new
@@ -68,6 +69,12 @@ class Unicorn::CGIWrapper < ::CGI
       @head[key] ||= value.join("\n") unless value.empty?
     end
 
+    # 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, @head, [ @body.string ] ]
   end
 
@@ -101,11 +108,11 @@ class Unicorn::CGIWrapper < ::CGI
           set_cookies << cookie.to_s
         end
       end
-      @status ||= (status = options.delete(STATUS)) # all lower-case
+      @status ||= options.delete(STATUS) # all lower-case
+
       # drop the keys we don't want anymore
       options.delete(NPH)
       options.delete(CONNECTION)
-      options.delete(Status) # Capitalized, with human-readable string
 
       # finally, set the rest of the headers as-is, allowing duplicates
       options.each_pair { |k,v| @headv[k] << v }