diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-19 10:10:06 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-19 17:04:37 -0700 |
commit | 60039518e03b0f1a0f530eefe008ebf72c55afe4 (patch) | |
tree | c31a8ff013634812ae71f7c935d309c652d5052a /t/file-wrap-to_path.ru | |
parent | 0cd65fa1e01be369b270c72053cf21a3d6bcb45f (diff) | |
download | rainbows-60039518e03b0f1a0f530eefe008ebf72c55afe4.tar.gz |
Middlewares like Clogger may wrap Rack::File responses with another body that responds to to_path and still rely on #close to trigger an action (writing out the log file).
Diffstat (limited to 't/file-wrap-to_path.ru')
-rw-r--r-- | t/file-wrap-to_path.ru | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/t/file-wrap-to_path.ru b/t/file-wrap-to_path.ru new file mode 100644 index 0000000..f12e08d --- /dev/null +++ b/t/file-wrap-to_path.ru @@ -0,0 +1,24 @@ +# must be run without Rack::Lint since that clobbers to_path +class Wrapper < Struct.new(:app) + def call(env) + status, headers, body = app.call(env) + body = Body.new(body) if body.respond_to?(:to_path) + [ status, headers, body ] + end + + class Body < Struct.new(:body) + def to_path + body.to_path + end + + def each(&block) + body.each(&block) + end + + def close + ::File.open(ENV['fifo'], 'wb') { |fp| fp.puts "CLOSING" } + end + end +end +use Wrapper +run Rack::File.new(Dir.pwd) |