mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add rack.after_reply to simplify logging and resources
This commit is contained in:
parent
0927fc8dc0
commit
be4a8336c0
2 changed files with 19 additions and 0 deletions
|
@ -242,6 +242,8 @@ module Puma
|
|||
|
||||
chunked = false
|
||||
|
||||
after_reply = env['rack.after_reply'] = []
|
||||
|
||||
begin
|
||||
begin
|
||||
status, headers, res_body = @app.call(env)
|
||||
|
@ -311,6 +313,8 @@ module Puma
|
|||
ensure
|
||||
body.close
|
||||
res_body.close if res_body.respond_to? :close
|
||||
|
||||
after_reply.each { |o| o.call }
|
||||
end
|
||||
|
||||
return keep_alive
|
||||
|
|
|
@ -73,4 +73,19 @@ class TestRackServer < Test::Unit::TestCase
|
|||
|
||||
assert_equal "/test/a/b/c", input['PATH_INFO']
|
||||
end
|
||||
|
||||
def test_after_reply
|
||||
closed = false
|
||||
|
||||
@server.app = lambda do |env|
|
||||
env['rack.after_reply'] << lambda { closed = true }
|
||||
@simple.call(env)
|
||||
end
|
||||
|
||||
@server.run
|
||||
|
||||
hit(['http://localhost:9998/test'])
|
||||
|
||||
assert_equal true, closed
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue