http_request: remove FIXME for rack.version clarification
[unicorn.git] / t / hijack.ru
blobfcb0b6d4939b121564ecb46a8f4e37fdc7df4af4
1 use Rack::Lint
2 use Rack::ContentLength
3 use Rack::ContentType, "text/plain"
4 class DieIfUsed
5   def each
6     abort "body.each called after response hijack\n"
7   end
9   def close
10     abort "body.close called after response hijack\n"
11   end
12 end
13 run lambda { |env|
14   case env["PATH_INFO"]
15   when "/hijack_req"
16     if env["rack.hijack?"]
17       io = env["rack.hijack"].call
18       if io.respond_to?(:read_nonblock) &&
19          env["rack.hijack_io"].respond_to?(:read_nonblock)
21         # exercise both, since we Rack::Lint may use different objects
22         env["rack.hijack_io"].write("HTTP/1.0 200 OK\r\n\r\n")
23         io.write("request.hijacked")
24         io.close
25         return [ 500, {}, DieIfUsed.new ]
26       end
27     end
28     [ 500, {}, [ "hijack BAD\n" ] ]
29   when "/hijack_res"
30     r = "response.hijacked"
31     [ 200,
32       {
33         "Content-Length" => r.bytesize.to_s,
34         "rack.hijack" => proc do |io|
35           io.write(r)
36           io.close
37         end
38       },
39       DieIfUsed.new
40     ]
41   end