Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix race condition in content length

  • Loading branch information...
commit e068683a3df0dd6c1ee58666ae4a307571abc368 1 parent 669deb4
@raggi raggi authored
Showing with 8 additions and 2 deletions.
  1. +5 −1 lib/rack/content_length.rb
  2. +3 −1 test/spec_content_length.rb
View
6 lib/rack/content_length.rb
@@ -1,4 +1,5 @@
require 'rack/utils'
+require 'rack/body_proxy'
module Rack
@@ -22,7 +23,10 @@ def call(env)
obody = body
body, length = [], 0
obody.each { |part| body << part; length += bytesize(part) }
- obody.close if obody.respond_to?(:close)
+
+ body = BodyProxy.new(body) do
+ obody.close if obody.respond_to?(:close)
+ end
headers['Content-Length'] = length.to_s
end
View
4 test/spec_content_length.rb
@@ -62,7 +62,9 @@ def to_ary; end
end.new(%w[one two three])
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
- content_length(app).call(request)
+ response = content_length(app).call(request)
+ body.closed.should.equal nil
+ response[2].close
body.closed.should.equal true
end
Please sign in to comment.
Something went wrong with that request. Please try again.