From 82d76cd654dfed2d1c4233f9a77c3a901c510133 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 13 Feb 2009 23:53:06 -0800 Subject: HttpResponse: remove crack-addled HTTP_STATUS_HEADERS hash This also fixes a subtle bug in header generation when the +$,+ ($OFS) variable is defined to something other than nil or "" I'm really wondering what kind of drugs I was on (or _not_ on) when I modified some of this from the Mongrel source. --- lib/unicorn/http_response.rb | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib/unicorn/http_response.rb') diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb index e67d2b3..7bbb940 100644 --- a/lib/unicorn/http_response.rb +++ b/lib/unicorn/http_response.rb @@ -21,12 +21,6 @@ module Unicorn class HttpResponse - # enforce "Connection: close" usage on all our responses - HTTP_STATUS_HEADERS = HTTP_STATUS_CODES.inject({}) do |hash, (code, text)| - hash[code] = "HTTP/1.1 #{code} #{text}\r\nConnection: close".freeze - hash - end.freeze - # headers we allow duplicates for ALLOWED_DUPLICATES = { 'Set-Cookie' => true, @@ -41,17 +35,20 @@ module Unicorn # Rack does not set/require Date, but don't worry about Content-Length # since Rack applications that conform to Rack::Lint enforce that - out = [ "#{Const::DATE}: #{Time.now.httpdate}\r\n" ] + out = [ "#{Const::DATE}: #{Time.now.httpdate}" ] sent = { Const::CONNECTION => true, Const::DATE => true } headers.each do |key, value| if ! sent[key] || ALLOWED_DUPLICATES[key] sent[key] = true - out << "#{key}: #{value}\r\n" + out << "#{key}: #{value}" end end - socket_write(socket, "#{HTTP_STATUS_HEADERS[status]}\r\n#{out.join}\r\n") + socket_write(socket, + "HTTP/1.1 #{status} #{HTTP_STATUS_CODES[status]}\r\n" \ + "Connection: close\r\n" \ + "#{out.join("\r\n")}\r\n\r\n") body.each { |chunk| socket_write(socket, chunk) } end -- cgit v1.2.3-24-ge0c7