From a0b8fe36d456b2dd339d65836a753ff4260dd8f6 Mon Sep 17 00:00:00 2001 From: Vais Salikhov Date: Tue, 4 Nov 2014 19:14:02 +0700 Subject: Ensure body is closed inside the proc just as it would be outside the proc Serving the body is wrapped in begin/ensure/end so that body.close is always called if there are any problems. Now that looping over the body happens in a proc, the proc has to have its own begin/ensure/end block to guarantee the same behavior. --- lib/rack/handler/webrick.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb index e96dce9a..b96d261e 100644 --- a/lib/rack/handler/webrick.rb +++ b/lib/rack/handler/webrick.rb @@ -112,7 +112,11 @@ module Rack body.each { |part| res.body << part } else res.body = proc do |socket| - body.each { |part| socket << part } + begin + body.each { |part| socket << part } + ensure + body.close if body.respond_to? :close + end end end end -- cgit v1.2.3-24-ge0c7