diff options
author | Dan Kubb <dan.kubb@gmail.com> | 2015-03-25 20:54:55 -0700 |
---|---|---|
committer | Dan Kubb <dan.kubb@gmail.com> | 2015-03-25 20:54:55 -0700 |
commit | a324b9294fb7e2846e57d62e6330b4d862ae906b (patch) | |
tree | 97b1cf5279a8ebfd45155ffa7f73a122d8f7ea3d /test/spec_lock.rb | |
parent | d5201119feaa2ed0fcaa37ae5fa1a293afafc437 (diff) | |
download | rack-a324b9294fb7e2846e57d62e6330b4d862ae906b.tar.gz |
Fix Rack::Lock to set env['rack.multithread'] properly
* The original code would set the flag for the duration of
Rack::Lock#call and then set it back when the method finished. The
problem is that the BodyProxy could be executing code that relies on
the state of the flag.
This change makes sure the application *and* the body proxy see the
expected state of the environment.
Diffstat (limited to 'test/spec_lock.rb')
-rw-r--r-- | test/spec_lock.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/test/spec_lock.rb b/test/spec_lock.rb index 4a44a0b4..099e806c 100644 --- a/test/spec_lock.rb +++ b/test/spec_lock.rb @@ -149,7 +149,10 @@ describe Rack::Lock do env['rack.multithread'].should.equal false [200, {"Content-Type" => "text/plain"}, %w{ a b c }] }, false) - app.call(Rack::MockRequest.env_for("/")) + env = Rack::MockRequest.env_for("/") + env['rack.multithread'].should.equal true + app.call(env) + env['rack.multithread'].should.equal true end should "reset original multithread flag when exiting lock" do @@ -174,4 +177,14 @@ describe Rack::Lock do lambda { app.call(env) }.should.raise(Exception) lock.unlocked?.should.equal false end + + should "not reset the environment while the body is proxied" do + proxy = Class.new do + attr_reader :env + def initialize(env) @env = env end + end + app = Rack::Lock.new lambda { |env| [200, {"Content-Type" => "text/plain"}, proxy.new(env)] } + response = app.call(Rack::MockRequest.env_for("/"))[2] + response.env['rack.multithread'].should.equal false + end end |