diff options
author | KITAITI Makoto <KitaitiMakoto@gmail.com> | 2014-04-14 02:22:27 +0900 |
---|---|---|
committer | KITAITI Makoto <KitaitiMakoto@gmail.com> | 2014-04-14 02:22:27 +0900 |
commit | 6aa56de9f7e07ca19fee5082c5498cd32a5a7012 (patch) | |
tree | 61ba8d994305f93e45131de4e0ce45bdfd99b203 | |
parent | adc2169e1e38e13b02f440c0124a4a734f5c2f64 (diff) | |
download | rack-6aa56de9f7e07ca19fee5082c5498cd32a5a7012.tar.gz |
Proxy body if it is fresh enough
In order to prevent response body resulting in race conditions.
-rw-r--r-- | lib/rack/conditionalget.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/rack/conditionalget.rb b/lib/rack/conditionalget.rb index 2c2113f2..88573166 100644 --- a/lib/rack/conditionalget.rb +++ b/lib/rack/conditionalget.rb @@ -25,11 +25,13 @@ module Rack status, headers, body = @app.call(env) headers = Utils::HeaderHash.new(headers) if status == 200 && fresh?(env, headers) - body.close if body.respond_to? :close status = 304 headers.delete('Content-Type') headers.delete('Content-Length') - body = [] + original_body = body + body = Rack::BodyProxy.new([]) do + original_body.close if original_body.respond_to?(:close) + end end [status, headers, body] else |