diff options
author | Vais Salikhov <vsalikhov@gmail.com> | 2014-11-04 19:14:02 +0700 |
---|---|---|
committer | Vais Salikhov <vsalikhov@gmail.com> | 2014-11-04 19:14:02 +0700 |
commit | a0b8fe36d456b2dd339d65836a753ff4260dd8f6 (patch) | |
tree | 9b4189e0122bdb150469764881e852a258e81195 | |
parent | a86456447d7de0a14decb5f8bda7c7a402b2e195 (diff) | |
download | rack-a0b8fe36d456b2dd339d65836a753ff4260dd8f6.tar.gz |
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.
-rw-r--r-- | lib/rack/handler/webrick.rb | 6 |
1 files changed, 5 insertions, 1 deletions
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 |