diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-04-16 15:04:28 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-04-16 15:06:41 -0700 |
commit | 66841a0164bc03eddb7a6ac31e3923302dbc5146 (patch) | |
tree | aa25c020b1d59bfe29aeb3b83baec51c968fd4d0 /lib/unicorn/http_response.rb | |
parent | c132287b0e0485412224e681244b453f5577479a (diff) | |
download | unicorn-66841a0164bc03eddb7a6ac31e3923302dbc5146.tar.gz |
There are weird (and possibly broken) clients out there that require it despite being present in the first line of the response. So be nice and accomodate them. Keep in mind that the Rack SPEC explicitly forbids this header from being in the headers returned by the Rack-based application; so we have to always inject it ourselves and ignore it if the application sets it.
Diffstat (limited to 'lib/unicorn/http_response.rb')
-rw-r--r-- | lib/unicorn/http_response.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index 98759f1..c0b1081 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -24,12 +24,16 @@ module Unicorn # Rack does not set/require a Date: header. We always override the # Connection: and Date: headers no matter what (if anything) our # Rack application sent us. - SKIP = { 'connection' => true, 'date' => true }.freeze + SKIP = { 'connection' => true, 'date' => true, 'status' => true }.freeze # writes the rack_response to socket as an HTTP response def self.write(socket, rack_response) status, headers, body = rack_response - out = [ "Date: #{Time.now.httpdate}" ] + status = "#{status} #{HTTP_STATUS_CODES[status]}" + + # Date is required by HTTP/1.1 as long as our clock can be trusted. + # Some broken clients require a "Status" header so we accomodate them + out = [ "Date: #{Time.now.httpdate}", "Status: #{status}" ] # Don't bother enforcing duplicate supression, it's a Hash most of # the time anyways so just hope our app knows what it's doing @@ -45,7 +49,7 @@ module Unicorn # Rack should enforce Content-Length or chunked transfer encoding, # so don't worry or care about them. socket_write(socket, - "HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status]}\r\n" \ + "HTTP/1.1 #{status}\r\n" \ "Connection: close\r\n" \ "#{out.join("\r\n")}\r\n\r\n") body.each { |chunk| socket_write(socket, chunk) } |