Skip to content

Instantly share code, notes, and snippets.

@jbr
Created October 11, 2009 02:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbr/207325 to your computer and use it in GitHub Desktop.
Save jbr/207325 to your computer and use it in GitHub Desktop.
class Rack::ResponseTimeInjector
def initialize(app, options = {})
@app = app
@format = options[:format] || "%f"
end
def call(env)
t0 = Time.now
returning @app.call(env) do |response|
response.last.body.gsub! /\$responsetime(?:\((.+)\))?/ do
diff = Time.now - t0
if @format.respond_to? :call
@format.call(diff)
else
($1 || @format) % diff
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment