From 06439cf6a5ad3034ab7da732449e59e473b3a7c6 Mon Sep 17 00:00:00 2001 From: macournoyer Date: Fri, 18 Apr 2008 15:27:07 -0400 Subject: [PATCH] Make sure app.deferred?(env) is only called once per request --- lib/thin/connection.rb | 3 ++- spec/connection_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/thin/connection.rb b/lib/thin/connection.rb index bda35dd9..22de983f 100644 --- a/lib/thin/connection.rb +++ b/lib/thin/connection.rb @@ -43,8 +43,10 @@ def receive_data(data) # is ready to be processed. def process if threaded? + @request.threaded = true EventMachine.defer(method(:pre_process), method(:post_process)) else + @request.threaded = false post_process(pre_process) end end @@ -52,7 +54,6 @@ def process def pre_process # Add client info to the request env @request.remote_address = remote_address - @request.threaded = threaded? # Process the request calling the Rack adapter @app.call(@request.env) diff --git a/spec/connection_spec.rb b/spec/connection_spec.rb index 08711c62..f1d435c7 100644 --- a/spec/connection_spec.rb +++ b/spec/connection_spec.rb @@ -71,8 +71,10 @@ end it "should set request env as rack.multithread" do + EventMachine.should_receive(:defer) + @connection.threaded = true - @connection.pre_process + @connection.process @connection.request.env["rack.multithread"].should == true end