about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-11-14 02:47:23 +0000
committerEric Wong <e@80x24.org>2015-11-18 02:20:23 +0000
commit9c9e3949b2ef2f299ff1590d23aa4d053b60a2fd (patch)
tree0ee6e193dc98e81a88a647b03e424c1d68516813
parent9f9f6a2f76e2dd0cd2ab6e6b4b591f93b21a6ddc (diff)
Applications may want to alter the message associated with HTTP
status codes in Rack::Utils::HTTP_STATUS_CODES.  Avoid memoizing
status lines ahead-of-time

Note: this introduces a minor performance regression, but ought to
be unnoticeable unless you're running "Hello world"-type apps.
-rw-r--r--lib/rainbows/response.rb5
-rw-r--r--lib/rainbows/stream_response_epoll.rb6
2 files changed, 6 insertions, 5 deletions
diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb
index db14ee4..a661ab6 100644
--- a/lib/rainbows/response.rb
+++ b/lib/rainbows/response.rb
@@ -40,8 +40,9 @@ module Rainbows::Response
   def write_headers(status, headers, alive, body)
     @hp.headers? or return body
     hijack = nil
-    status = CODES[status.to_i] || status
-    buf = "HTTP/1.1 #{status}\r\n" \
+    code = status.to_i
+    msg = Rack::Utils::HTTP_STATUS_CODES[code]
+    buf = "HTTP/1.1 #{msg ? %Q(#{code} #{msg}) : status}\r\n" \
           "Date: #{httpdate}\r\n"
     headers.each do |key, value|
       case key
diff --git a/lib/rainbows/stream_response_epoll.rb b/lib/rainbows/stream_response_epoll.rb
index c0d90a4..1f32dcc 100644
--- a/lib/rainbows/stream_response_epoll.rb
+++ b/lib/rainbows/stream_response_epoll.rb
@@ -20,18 +20,18 @@ require "raindrops"
 # * sleepy_penguin 3.0.1 or later
 module Rainbows::StreamResponseEpoll
   # :stopdoc:
-  CODES = Unicorn::HttpResponse::CODES
   HEADER_END = "X-Accel-Buffering: no\r\n\r\n"
   autoload :Client, "rainbows/stream_response_epoll/client"
 
   def http_response_write(socket, status, headers, body)
-    status = CODES[status.to_i] || status
     hijack = ep_client = false
 
     if headers
       # don't set extra headers here, this is only intended for
       # consuming by nginx.
-      buf = "HTTP/1.0 #{status}\r\n"
+      code = status.to_i
+      msg = Rack::Utils::HTTP_STATUS_CODES[code]
+      buf = "HTTP/1.0 #{msg ? %Q(#{code} #{msg}) : status}\r\n"
       headers.each do |key, value|
         case key
         when "rack.hijack"