module Rack class LoadSpeed def initialize(app) @app = app end def call(env) env.delete("HTTP_IF_NONE_MATCH") status, headers, response = @app.call(env) if status == 200 body = response.body index = body.rindex("") if index body.insert(index, performance_code) headers["Content-Length"] = body.length.to_s response = [body] end end [status, headers, response] end protected def performance_code html = <<-EOF
#{StopwatchLog.event.duration.to_i} ms #{StopwatchLog.query_count} queries
EOF html end end end