From 3d69a6f064078eeb28c1819725d3715ce6905374 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 27 Jan 2016 00:08:19 +0000 Subject: rack is optional at runtime, required for dev 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 Thanks-to: Aaron Patterson --- lib/unicorn/http_response.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/unicorn/http_response.rb') 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" \ -- cgit v1.2.3-24-ge0c7