Permalink
Browse files

Fix race conditions from ETag middleware with lock

  • Loading branch information...
raggi committed Dec 28, 2013
1 parent 24935a5 commit 669deb49dbb571d2f10ddb67fcd8049c5dabf42f
Showing with 7 additions and 3 deletions.
  1. +4 −2 lib/rack/etag.rb
  2. +3 −1 test/spec_etag.rb
View
@@ -24,8 +24,10 @@ def call(env)
if etag_status?(status) && etag_body?(body) && !skip_caching?(headers)
original_body = body
- digest, body = digest_body(body)
- original_body.close if original_body.respond_to?(:close)
+ digest, new_body = digest_body(body)
+ body = Rack::BodyProxy.new(new_body) do
+ original_body.close if original_body.respond_to?(:close)
+ end
headers['ETag'] = %("#{digest}") if digest
end
View
@@ -99,7 +99,9 @@ def res.to_path ; "/tmp/hello.txt" ; end
should "close the original body" do
body = StringIO.new
app = lambda { |env| [200, {}, body] }
- etag(app).call(request)
+ response = etag(app).call(request)
+ body.should.not.be.closed
+ response[2].close
body.should.be.closed
end
end

0 comments on commit 669deb4

Please sign in to comment.