about summary refs log tree commit homepage
path: root/lib/rainbows/stream_file.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-07-19 10:10:06 +0000
committerEric Wong <normalperson@yhbt.net>2010-07-19 17:04:37 -0700
commit60039518e03b0f1a0f530eefe008ebf72c55afe4 (patch)
treec31a8ff013634812ae71f7c935d309c652d5052a /lib/rainbows/stream_file.rb
parent0cd65fa1e01be369b270c72053cf21a3d6bcb45f (diff)
downloadrainbows-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 'lib/rainbows/stream_file.rb')
-rw-r--r--lib/rainbows/stream_file.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/rainbows/stream_file.rb b/lib/rainbows/stream_file.rb
index f533f18..dec58b0 100644
--- a/lib/rainbows/stream_file.rb
+++ b/lib/rainbows/stream_file.rb
@@ -5,10 +5,11 @@
 # models.  We always maintain our own file offsets in userspace because
 # because sendfile() implementations offer pread()-like idempotency for
 # concurrency (multiple clients can read the same underlying file handle).
-class Rainbows::StreamFile < Struct.new(:offset, :to_io)
+class Rainbows::StreamFile < Struct.new(:offset, :to_io, :body)
 
   def close
-    to_io.close
+    body.close if body.respond_to?(:close)
+    to_io.close unless to_io.closed?
     self.to_io = nil
   end
 end