From 60039518e03b0f1a0f530eefe008ebf72c55afe4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Jul 2010 10:10:06 +0000 Subject: ensure file response bodies are properly closed 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). --- lib/rainbows/event_machine.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/rainbows/event_machine.rb') diff --git a/lib/rainbows/event_machine.rb b/lib/rainbows/event_machine.rb index 4faa7a6..696f5a0 100644 --- a/lib/rainbows/event_machine.rb +++ b/lib/rainbows/event_machine.rb @@ -121,7 +121,10 @@ module Rainbows if st.file? write(response_header(status, headers)) if headers @body = stream = stream_file_data(body.to_path) - stream.callback { quit } unless alive + stream.callback do + body.close if body.respond_to?(:close) + quit unless alive + end return elsif st.socket? || st.pipe? chunk = stream_response_headers(status, headers) if headers -- cgit v1.2.3-24-ge0c7