about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-02-13 23:53:06 -0800
committerEric Wong <normalperson@yhbt.net>2009-02-14 00:32:23 -0800
commit82d76cd654dfed2d1c4233f9a77c3a901c510133 (patch)
tree9f1e9c9ec6cf3d743181d4951478d072d224f2c9 /lib
parent92f412c8ead79524da5b823028dda14864f7f8ae (diff)
downloadunicorn-82d76cd654dfed2d1c4233f9a77c3a901c510133.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/unicorn/http_response.rb15
1 files changed, 6 insertions, 9 deletions
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