From b2569b344d61a7d26033aeb6198d23f99d2e7f3e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 1 Apr 2009 01:19:27 -0700 Subject: cgi_wrapper: HTTP status code cleanups 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. --- lib/unicorn/cgi_wrapper.rb | 13 ++++++++++--- 1 file 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 } -- cgit v1.2.3-24-ge0c7