diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-08-17 08:35:03 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-08-17 08:41:15 +0000 |
commit | ac05e7035e1946b78ce4679548db7680aa01734c (patch) | |
tree | 1379997b2686b9fa777216ad06f1ffe9be5b6027 /t/close-pipe-to_path-response.ru | |
parent | 9c5669e232f8f57c2d8e08d84e21bf09cd87bfa1 (diff) | |
download | rainbows-ac05e7035e1946b78ce4679548db7680aa01734c.tar.gz |
First off we use an FD_MAP to avoid creating redundant IO objects which map to the same FD. When that doesn't work, we'll fall back to trapping Errno::EBADF and IOError where appropriate.
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 ] +}) |