coolio+xepoll_thread*: use shutdown() for keepalive timeout
[rainbows.git] / t / close-pipe-to_path-response.ru
blobabc3a37c09869ed3992084425dde79f1dfa96846
1 # must be run without Rack::Lint since that clobbers to_path
2 class MyMiddleware < Struct.new(:app)
3   class Body < Struct.new(:body, :to_path)
4     def each(&block); body.each(&block); end
5     def close
6       c = body.respond_to?(:close)
7       ::File.open(ENV['fifo'], 'wb') do |fp|
8         fp.syswrite("CLOSING #{body.inspect} #{to_path} (#{c})\n")
9       end
10       body.close if c
11     end
12   end
14   def call(env)
15     status, headers, body = app.call(env)
16     body.respond_to?(:to_path) and body = Body.new(body, body.to_path)
17     [ status, headers, body ]
18   end
19 end
20 use MyMiddleware
21 use Rainbows::DevFdResponse
22 run(lambda { |env|
23   io = IO.popen('cat random_blob', 'rb')
24   [ 200,
25     {
26       'Content-Length' => ::File.stat('random_blob').size.to_s,
27       'Content-Type' => 'application/octet-stream',
28     },
29     io ]