about summary refs log tree commit homepage
path: root/lib/rainbows/process_client.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-08 22:45:20 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-11 01:57:05 +0000
commite166cfe5e8d648b544b1291ec157bd234a425e21 (patch)
tree8ac56aadc51d81d4d250cfec696446f19ffd1d64 /lib/rainbows/process_client.rb
parente6faf9e26bcb172026a4984ecadbaa8b6789bcb7 (diff)
downloadrainbows-e166cfe5e8d648b544b1291ec157bd234a425e21.tar.gz
This requires Rack 1.5.x and unicorn 4.6.0 for hijacking
support.  Older versions of Rack continue to work fine,
but we must use unicorn 4.6.0 features to support this.
Diffstat (limited to 'lib/rainbows/process_client.rb')
-rw-r--r--lib/rainbows/process_client.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/rainbows/process_client.rb b/lib/rainbows/process_client.rb
index b685001..f58770c 100644
--- a/lib/rainbows/process_client.rb
+++ b/lib/rainbows/process_client.rb
@@ -40,6 +40,7 @@ module Rainbows::ProcessClient
 
       set_input(env, hp)
       env[REMOTE_ADDR] = kgio_addr
+      hp.hijack_setup(env, to_io)
       status, headers, body = APP.call(env.merge!(RACK_DEFAULTS))
 
       if 100 == status.to_i
@@ -47,7 +48,8 @@ module Rainbows::ProcessClient
         env.delete(HTTP_EXPECT)
         status, headers, body = APP.call(env)
       end
-      write_response(status, headers, body, alive = @hp.next?)
+      return if hp.hijacked?
+      write_response(status, headers, body, alive = hp.next?) or return
     end while alive
   # if we get any error, try to write something back to the client
   # assuming we haven't closed the socket, but don't get hung up
@@ -56,7 +58,7 @@ module Rainbows::ProcessClient
   rescue => e
     handle_error(e)
   ensure
-    close unless closed?
+    close unless closed? || hp.hijacked?
   end
 
   def handle_error(e)
@@ -71,13 +73,15 @@ module Rainbows::ProcessClient
     begin
       set_input(env, hp)
       env[REMOTE_ADDR] = kgio_addr
+      hp.hijack_setup(env, to_io)
       status, headers, body = APP.call(env.merge!(RACK_DEFAULTS))
       if 100 == status.to_i
         write(EXPECT_100_RESPONSE)
         env.delete(HTTP_EXPECT)
         status, headers, body = APP.call(env)
       end
-      write_response(status, headers, body, alive = hp.next?)
+      return if hp.hijacked?
+      write_response(status, headers, body, alive = hp.next?) or return
     end while alive && pipeline_ready(hp)
     alive or close
     rescue => e