about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-11-14 02:47:25 +0000
committerEric Wong <e@80x24.org>2015-11-18 02:20:26 +0000
commit1a2a82721bf845a3f7e7a3972bc0f41befb25c41 (patch)
tree98da87ea5d5293b31fa3fd463b6d70b3059a1be3
parent70c976bdd85bb8515fea01d6ad6074ef472fc2e0 (diff)
unicorn lost the hijack_setup method in version 5,
so we must recreate it ourselves.
-rw-r--r--lib/rainbows/coolio/client.rb2
-rw-r--r--lib/rainbows/coolio/thread_client.rb2
-rw-r--r--lib/rainbows/epoll/client.rb2
-rw-r--r--lib/rainbows/event_machine/client.rb2
-rw-r--r--lib/rainbows/http_parser.rb9
-rw-r--r--lib/rainbows/process_client.rb4
-rw-r--r--lib/rainbows/response.rb16
7 files changed, 18 insertions, 19 deletions
diff --git a/lib/rainbows/coolio/client.rb b/lib/rainbows/coolio/client.rb
index c05fd3a..ad827f6 100644
--- a/lib/rainbows/coolio/client.rb
+++ b/lib/rainbows/coolio/client.rb
@@ -125,7 +125,7 @@ class Rainbows::Coolio::Client < Coolio::IO
     @env['rack.input'] = input
     @env['REMOTE_ADDR'] = @_io.kgio_addr
     @env['async.callback'] = method(:write_async_response)
-    @hp.hijack_setup(@env, @_io)
+    @hp.hijack_setup(@_io)
     status, headers, body = catch(:async) {
       APP.call(@env.merge!(RACK_DEFAULTS))
     }
diff --git a/lib/rainbows/coolio/thread_client.rb b/lib/rainbows/coolio/thread_client.rb
index 4de705f..a3a2ebf 100644
--- a/lib/rainbows/coolio/thread_client.rb
+++ b/lib/rainbows/coolio/thread_client.rb
@@ -26,7 +26,7 @@ class Rainbows::Coolio::ThreadClient < Rainbows::Coolio::Client
   def app_response
     begin
       @env['REMOTE_ADDR'] = @_io.kgio_addr
-      @hp.hijack_setup(@env, @_io)
+      @hp.hijack_setup(@_io)
       APP.call(@env.merge!(RACK_DEFAULTS))
     rescue => e
       Rainbows::Error.app(e) # we guarantee this does not raise
diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb
index 2d95a99..6dcbb81 100644
--- a/lib/rainbows/epoll/client.rb
+++ b/lib/rainbows/epoll/client.rb
@@ -65,7 +65,7 @@ module Rainbows::Epoll::Client
   def app_call input # called by on_read()
     @env['rack.input'] = input
     @env['REMOTE_ADDR'] = kgio_addr
-    @hp.hijack_setup(@env, self)
+    @hp.hijack_setup(self)
     status, headers, body = APP.call(@env.merge!(RACK_DEFAULTS))
     return hijacked if @hp.hijacked?
     ev_write_response(status, headers, body, @hp.next?)
diff --git a/lib/rainbows/event_machine/client.rb b/lib/rainbows/event_machine/client.rb
index 7fb88f6..039b7a6 100644
--- a/lib/rainbows/event_machine/client.rb
+++ b/lib/rainbows/event_machine/client.rb
@@ -38,7 +38,7 @@ class Rainbows::EventMachine::Client < EM::Connection
     @env['REMOTE_ADDR'] = @_io.kgio_addr
     @env['async.callback'] = method(:write_async_response)
     @env['async.close'] = EM::DefaultDeferrable.new
-    @hp.hijack_setup(@env, @_io)
+    @hp.hijack_setup(@_io)
     status, headers, body = catch(:async) {
       APP.call(@env.merge!(RACK_DEFAULTS))
     }
diff --git a/lib/rainbows/http_parser.rb b/lib/rainbows/http_parser.rb
index 30a67cb..bcf1dba 100644
--- a/lib/rainbows/http_parser.rb
+++ b/lib/rainbows/http_parser.rb
@@ -17,6 +17,15 @@ class Rainbows::HttpParser < Unicorn::HttpParser
     super
   end
 
+  def hijack_setup(io)
+    @hijack_io = io
+    env['rack.hijack'] = self # avoid allocating a new proc this way
+  end
+
+  def call # for rack.hijack
+    env['rack.hijack_io'] = @hijack_io
+  end
+
   def self.quit
     alias_method :next?, :never!
   end
diff --git a/lib/rainbows/process_client.rb b/lib/rainbows/process_client.rb
index 492b8a6..a39d6cd 100644
--- a/lib/rainbows/process_client.rb
+++ b/lib/rainbows/process_client.rb
@@ -39,7 +39,7 @@ module Rainbows::ProcessClient
 
       set_input(env, hp)
       env['REMOTE_ADDR'] = kgio_addr
-      hp.hijack_setup(env, to_io)
+      hp.hijack_setup(to_io)
       status, headers, body = APP.call(env.merge!(RACK_DEFAULTS))
 
       if 100 == status.to_i
@@ -72,7 +72,7 @@ module Rainbows::ProcessClient
     begin
       set_input(env, hp)
       env['REMOTE_ADDR'] = kgio_addr
-      hp.hijack_setup(env, to_io)
+      hp.hijack_setup(to_io)
       status, headers, body = APP.call(env.merge!(RACK_DEFAULTS))
       if 100 == status.to_i
         write("HTTP/1.1 100 Continue\r\n\r\n".freeze)
diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb
index 2e8d2d8..0b5e542 100644
--- a/lib/rainbows/response.rb
+++ b/lib/rainbows/response.rb
@@ -15,18 +15,8 @@ module Rainbows::Response
       Rainbows::HttpParser.keepalive_requests = 0
   end
 
-  # Rack 1.5.0 (protocol version 1.2) adds response hijacking support
-  if ((Rack::VERSION[0] << 8) | Rack::VERSION[1]) >= 0x0102
-    def hijack_prepare(value)
-      value
-    end
-
-    def hijack_socket
-      @hp.env['rack.hijack'].call
-    end
-  else
-    def hijack_prepare(_)
-    end
+  def hijack_socket
+    @hp.env['rack.hijack'].call
   end
 
   # returns the original body on success
@@ -45,7 +35,7 @@ module Rainbows::Response
       when "rack.hijack"
         # this was an illegal key in Rack < 1.5, so it should be
         # OK to silently discard it for those older versions
-        hijack = hijack_prepare(value)
+        hijack = value
         alive = false # No persistent connections for hijacking
       else
         if /\n/ =~ value