about summary refs log tree commit homepage
path: root/lib/unicorn/http_request.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicorn/http_request.rb')
-rw-r--r--lib/unicorn/http_request.rb16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb
index b32003e..b60e383 100644
--- a/lib/unicorn/http_request.rb
+++ b/lib/unicorn/http_request.rb
@@ -97,15 +97,21 @@ class Unicorn::HttpParser
 
     e[RACK_INPUT] = 0 == content_length ?
                     NULL_IO : @@input_class.new(socket, self)
-    hijack_setup(e, socket)
+
+    # for Rack hijacking in Rack 1.5 and later
+    @socket = socket
+    e[RACK_HIJACK] = self
+
     e.merge!(DEFAULTS)
   end
 
-  def hijacked?
-    env.include?(RACK_HIJACK_IO)
+  # for rack.hijack, we respond to this method so no extra allocation
+  # of a proc object
+  def call
+    env[RACK_HIJACK_IO] = @socket
   end
 
-  def hijack_setup(e, socket)
-    e[RACK_HIJACK] = proc { e[RACK_HIJACK_IO] = socket }
+  def hijacked?
+    env.include?(RACK_HIJACK_IO)
   end
 end