diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-01-22 11:04:52 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-01-22 11:43:06 +0000 |
commit | 705cf5fcf8ccb37deef5d2b922d6d78d34765c5b (patch) | |
tree | 19b250d132aa1c4f9a50b59d1096cf4ce8a34122 /t/hijack.ru | |
parent | faf1edc74c9bb35cf4e131d794c1923bf124aa1c (diff) | |
download | unicorn-705cf5fcf8ccb37deef5d2b922d6d78d34765c5b.tar.gz |
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.
Diffstat (limited to 't/hijack.ru')
-rw-r--r-- | t/hijack.ru | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/t/hijack.ru b/t/hijack.ru new file mode 100644 index 0000000..105e0d7 --- /dev/null +++ b/t/hijack.ru @@ -0,0 +1,37 @@ +use Rack::Lint +use Rack::ContentLength +use Rack::ContentType, "text/plain" +class DieIfUsed + def each + abort "body.each called after response hijack\n" + end + + def close + abort "body.close called after response hijack\n" + end +end +run lambda { |env| + case env["PATH_INFO"] + when "/hijack_req" + if env["rack.hijack?"] + io = env["rack.hijack"].call + if io.respond_to?(:read_nonblock) && + env["rack.hijack_io"].respond_to?(:read_nonblock) + return [ 200, {}, [ "hijack.OK\n" ] ] + end + end + [ 500, {}, [ "hijack BAD\n" ] ] + when "/hijack_res" + r = "response.hijacked" + [ 200, + { + "Content-Length" => r.bytesize.to_s, + "rack.hijack" => proc do |io| + io.write(r) + io.close + end + }, + DieIfUsed.new + ] + end +} |