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 /lib/rainbows/dev_fd_response.rb | |
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 'lib/rainbows/dev_fd_response.rb')
-rw-r--r-- | lib/rainbows/dev_fd_response.rb | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index 451cad7..691526c 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -36,6 +36,7 @@ class Rainbows::DevFdResponse < Struct.new(:app) headers = HeaderHash.new(headers) st = io.stat + fileno = io.fileno if st.file? headers['Content-Length'] ||= st.size.to_s headers.delete('Transfer-Encoding') @@ -51,15 +52,15 @@ class Rainbows::DevFdResponse < Struct.new(:app) # we need to make sure our pipe output is Fiber-compatible case env["rainbows.model"] when :FiberSpawn, :FiberPool, :RevFiberSpawn - return [ status, headers, Rainbows::Fiber::IO.new(io,::Fiber.current) ] + io = Rainbows::Fiber::IO.new(io,::Fiber.current) end else # unlikely, char/block device file, directory, ... return response end - [ status, headers, Body.new(io, "/dev/fd/#{io.fileno}") ] + [ status, headers, Body.new(io, "/dev/fd/#{fileno}", body) ] end - class Body < Struct.new(:to_io, :to_path) + class Body < Struct.new(:to_io, :to_path, :orig_body) # called by the webserver or other middlewares if they can't # handle #to_path def each(&block) @@ -74,7 +75,8 @@ class Rainbows::DevFdResponse < Struct.new(:app) # called by the web server after #each def close - to_io.close if to_io.respond_to?(:close) + to_io.close unless to_io.closed? + orig_body.close if orig_body.respond_to?(:close) # may not be an IO rescue IOError # could've been IO::new()'ed and closed end end |