diff options
Diffstat (limited to 't/close-pipe-to_path-response.ru')
-rw-r--r-- | t/close-pipe-to_path-response.ru | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/t/close-pipe-to_path-response.ru b/t/close-pipe-to_path-response.ru new file mode 100644 index 0000000..abc3a37 --- /dev/null +++ b/t/close-pipe-to_path-response.ru @@ -0,0 +1,30 @@ +# must be run without Rack::Lint since that clobbers to_path +class MyMiddleware < Struct.new(:app) + class Body < Struct.new(:body, :to_path) + def each(&block); body.each(&block); end + def close + c = body.respond_to?(:close) + ::File.open(ENV['fifo'], 'wb') do |fp| + fp.syswrite("CLOSING #{body.inspect} #{to_path} (#{c})\n") + end + body.close if c + end + end + + def call(env) + status, headers, body = app.call(env) + body.respond_to?(:to_path) and body = Body.new(body, body.to_path) + [ status, headers, body ] + end +end +use MyMiddleware +use Rainbows::DevFdResponse +run(lambda { |env| + io = IO.popen('cat random_blob', 'rb') + [ 200, + { + 'Content-Length' => ::File.stat('random_blob').size.to_s, + 'Content-Type' => 'application/octet-stream', + }, + io ] +}) |