diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-19 10:10:05 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-19 17:04:35 -0700 |
commit | 0cd65fa1e01be369b270c72053cf21a3d6bcb45f (patch) | |
tree | 7ae76d0860f740838faa9cb5172b100b7a58a35c /t/close-pipe-response.ru | |
parent | ed14b9bdbb35fa18dc283ba2d048a33d10759b2d (diff) | |
download | rainbows-0cd65fa1e01be369b270c72053cf21a3d6bcb45f.tar.gz |
Some middlewares such as Clogger rely on wrapping the body having the close method called on it for logging.
Diffstat (limited to 't/close-pipe-response.ru')
-rw-r--r-- | t/close-pipe-response.ru | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/t/close-pipe-response.ru b/t/close-pipe-response.ru new file mode 100644 index 0000000..96116d4 --- /dev/null +++ b/t/close-pipe-response.ru @@ -0,0 +1,26 @@ +# must be run without Rack::Lint since that clobbers to_path +class CloseWrapper < Struct.new(:to_io) + def each(&block) + to_io.each(&block) + end + + def close + ::File.open(ENV['fifo'], 'wb') do |fp| + fp.syswrite("CLOSING #{to_io}\n") + if to_io.respond_to?(:close) && ! to_io.closed? + to_io.close + end + end + end +end +use Rainbows::DevFdResponse +run(lambda { |env| + body = 'hello world' + io = IO.popen("echo '#{body}'", 'rb') + [ 200, + { + 'Content-Length' => (body.size + 1).to_s, + 'Content-Type' => 'application/octet-stream', + }, + CloseWrapper[io] ] +}) |