From 705cf5fcf8ccb37deef5d2b922d6d78d34765c5b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Jan 2013 11:04:52 +0000 Subject: support for Rack hijack in request and response Rack 1.5.0 (protocol version [1,2]) adds support for hijacking the client socket (removing it from the control of unicorn (or any other Rack webserver)). Tested with rack 1.5.0. --- lib/unicorn/http_request.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib/unicorn/http_request.rb') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 79ead2e..3bc64ed 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -91,6 +91,27 @@ class Unicorn::HttpParser e[RACK_INPUT] = 0 == content_length ? NULL_IO : @@input_class.new(socket, self) + hijack_setup(e, socket) 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 + + # FIXME: asking for clarification about this in + # http://mid.gmane.org/20130122100802.GA28585@dcvr.yhbt.net + DEFAULTS["rack.version"] = [1, 2] + + RACK_HIJACK = "rack.hijack".freeze + RACK_HIJACK_IO = "rack.hijack_io".freeze + + 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 + end end -- cgit v1.2.3-24-ge0c7 From fedb5e50829e6dfad30ca18ea525c812eccbec70 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 22 Jan 2013 23:52:14 +0000 Subject: ignore normal Rack response at request-time hijack Once a connection is hijacked, we ignore it completely and leave the connection at the mercy of the application. --- lib/unicorn/http_request.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/unicorn/http_request.rb') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 3bc64ed..3795b3b 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -106,6 +106,10 @@ class Unicorn::HttpParser 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 @@ -113,5 +117,9 @@ class Unicorn::HttpParser # old Rack, do nothing. def hijack_setup(e, _) end + + def hijacked? + false + end end end -- cgit v1.2.3-24-ge0c7