From e166cfe5e8d648b544b1291ec157bd234a425e21 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 8 Feb 2013 22:45:20 +0000 Subject: hijacking support for Rack 1.5.x users 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. --- lib/rainbows/process_client.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/rainbows/process_client.rb') 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 -- cgit v1.2.3-24-ge0c7