From fdf09e562733f9509d275cb13c1c1a04e579a68a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 May 2015 21:43:42 +0000 Subject: http_request: support rack.hijack by default Rack 1.4 and earlier will soon die out, so avoid having extra code The only minor overhead is assigning two hash slots and the extra hash checks when running ancient versions of Rack, so it is unlikely anybody cares about that overhead with Rack 1.5 and later. --- lib/unicorn/http_request.rb | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 9888430..b32003e 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -13,13 +13,16 @@ class Unicorn::HttpParser "rack.multiprocess" => true, "rack.multithread" => false, "rack.run_once" => false, - "rack.version" => [1, 1], + "rack.version" => [1, 2], + "rack.hijack?" => true, "SCRIPT_NAME" => "", # this is not in the Rack spec, but some apps may rely on it "SERVER_SOFTWARE" => "Unicorn #{Unicorn::Const::UNICORN_VERSION}" } + RACK_HIJACK = "rack.hijack".freeze + RACK_HIJACK_IO = "rack.hijack_io".freeze NULL_IO = StringIO.new("") attr_accessor :response_start_sent @@ -98,28 +101,11 @@ class Unicorn::HttpParser e.merge!(DEFAULTS) end - # Rack 1.5.0 (protocol version 1.2) adds hijack request support - if ((Rack::VERSION[0] << 8) | Rack::VERSION[1]) >= 0x0102 - DEFAULTS["rack.hijack?"] = true - DEFAULTS["rack.version"] = [1, 2] - - RACK_HIJACK = "rack.hijack".freeze - RACK_HIJACK_IO = "rack.hijack_io".freeze - - def hijacked? - env.include?(RACK_HIJACK_IO) - end - - def hijack_setup(e, socket) - e[RACK_HIJACK] = proc { e[RACK_HIJACK_IO] = socket } - end - else - # old Rack, do nothing. - def hijack_setup(e, _) - end + def hijacked? + env.include?(RACK_HIJACK_IO) + end - def hijacked? - false - end + def hijack_setup(e, socket) + e[RACK_HIJACK] = proc { e[RACK_HIJACK_IO] = socket } end end -- cgit v1.2.3-24-ge0c7