Skip to content
Browse files

Simplify BodyProxy#close to avoid horrible loop conditions in streaming

scenarios, and save users from themselves
  • Loading branch information...
1 parent 2bdc3e1 commit 0c26ffeeac330216b66c1e2d621c02943c4787e4 @raggi raggi committed
Showing with 6 additions and 11 deletions.
  1. +4 −7 lib/rack/body_proxy.rb
  2. +2 −4 test/spec_body_proxy.rb
View
11 lib/rack/body_proxy.rb
@@ -9,13 +9,10 @@ def respond_to?(*args)
end
def close
- raise IOError, "closed stream" if @closed
- begin
- @closed = true
- @body.close if @body.respond_to? :close
- ensure
- @block.call
- end
+ return if @closed
+ @closed = true
+ @body.close if @body.respond_to? :close
+ @block.call
end
def closed?
View
6 test/spec_body_proxy.rb
@@ -35,10 +35,8 @@
should 'not close more than one time' do
count = 0
proxy = Rack::BodyProxy.new([]) { count += 1; raise "Block invoked more than 1 time!" if count > 1 }
- proxy.close
- lambda {
- proxy.close
- }.should.raise(IOError)
+ 2.times { proxy.close }
+ count.should.equal 1
end
should 'be closed when the callback is triggered' do

1 comment on commit 0c26ffe

@rkh
Official Rack repositories member

Can I haz another release?

Please sign in to comment.
Something went wrong with that request. Please try again.