summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-05-07 21:43:42 +0000
committerEric Wong <e@80x24.org>2015-05-16 21:23:57 +0000
commitfdf09e562733f9509d275cb13c1c1a04e579a68a (patch)
treed6718748b1c178d07b6f99a6bc69a282e6c84da7
parentd032af0b4aba8df8433250ae6372c64dfab299f9 (diff)
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.
-rw-r--r--lib/unicorn/http_request.rb32
1 files 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