Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 28 lines (24 sloc) 0.71 kb
37195be @josh Import runtime middleware by paul (Paul Sadauskas) into core
josh authored
1 module Rack
2 # Sets an "X-Runtime" response header, indicating the response
3 # time of the request, in seconds
4 #
5 # You can put it right before the application to see the processing
6 # time, or before all the other middlewares to include time for them,
7 # too.
8 class Runtime
9 def initialize(app, name = nil)
10 @app = app
11 @header_name = "X-Runtime"
12 @header_name << "-#{name}" if name
13 end
14
15 def call(env)
16 start_time = Time.now
17 status, headers, body = @app.call(env)
18 request_time = Time.now - start_time
19
20 if !headers.has_key?(@header_name)
21 headers[@header_name] = "%0.6f" % request_time
22 end
23
24 [status, headers, body]
25 end
26 end
27 end
Something went wrong with that request. Please try again.