about summary refs log tree commit homepage
path: root/lib/unicorn
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-01-27 00:08:19 +0000
committerEric Wong <e@80x24.org>2016-01-27 00:28:01 +0000
commit3d69a6f064078eeb28c1819725d3715ce6905374 (patch)
treefc8400bf722ae60869043711df57a932c5137c01 /lib/unicorn
parent7c0271ef26dd41eb0fc1ca3370883c49a45b2dec (diff)
downloadunicorn-3d69a6f064078eeb28c1819725d3715ce6905374.tar.gz
We do not want to pull in a newer or older version of rack depending
on an the application running under it requires.  Furthermore, it
has always been possible to use unicorn without any middleware at
all.

Without rack, we'll be missing descriptive status text in the first
response line, but any valid HTTP/1.x parser should be able to
handle it properly.

ref:
 http://bogomips.org/unicorn-public/20160121201255.GA6186@dcvr.yhbt.net/t/#u

Thanks-to: Adam Duke <adam.v.duke@gmail.com>
Thanks-to: Aaron Patterson <tenderlove@ruby-lang.org>
Diffstat (limited to 'lib/unicorn')
-rw-r--r--lib/unicorn/http_response.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb
index 7b446c2..ec128e4 100644
--- a/lib/unicorn/http_response.rb
+++ b/lib/unicorn/http_response.rb
@@ -10,10 +10,13 @@
 # is the job of Rack, with the exception of the "Date" and "Status" header.
 module Unicorn::HttpResponse
 
+  STATUS_CODES = defined?(Rack::Utils::HTTP_STATUS_CODES) ?
+                 Rack::Utils::HTTP_STATUS_CODES : {}
+
   # internal API, code will always be common-enough-for-even-old-Rack
   def err_response(code, response_start_sent)
     "#{response_start_sent ? '' : 'HTTP/1.1 '}" \
-      "#{code} #{Rack::Utils::HTTP_STATUS_CODES[code]}\r\n\r\n"
+      "#{code} #{STATUS_CODES[code]}\r\n\r\n"
   end
 
   # writes the rack_response to socket as an HTTP response
@@ -23,7 +26,7 @@ module Unicorn::HttpResponse
 
     if headers
       code = status.to_i
-      msg = Rack::Utils::HTTP_STATUS_CODES[code]
+      msg = STATUS_CODES[code]
       start = response_start_sent ? ''.freeze : 'HTTP/1.1 '.freeze
       buf = "#{start}#{msg ? %Q(#{code} #{msg}) : status}\r\n" \
             "Date: #{httpdate}\r\n" \