1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma/rack_patch.rb
2011-12-01 15:23:14 -08:00

25 lines
592 B
Ruby

require 'rack/commonlogger'
module Rack
# Patch CommonLogger to use after_reply.
#
# Simply request this file and CommonLogger will be a bit more
# efficient.
class CommonLogger
remove_method :call
def call(env)
began_at = Time.now
status, header, body = @app.call(env)
header = Utils::HeaderHash.new(header)
if ary = env['rack.after_reply']
ary << lambda { log(env, status, header, began_at) }
else
body = BodyProxy.new(body) { log(env, status, header, began_at) }
end
[status, header, body]
end
end
end