Skip to content

Commit

Permalink
Make sure app.deferred?(env) is only called once per request
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Apr 18, 2008
1 parent c90f50f commit 06439cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/thin/connection.rb
Expand Up @@ -43,16 +43,17 @@ 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

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)
Expand Down
4 changes: 3 additions & 1 deletion spec/connection_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 06439cf

Please sign in to comment.