Created
April 19, 2010 03:45
-
-
Save teepark/370730 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
class TimerMiddleware(object): | |
'a WSGI middleware that sends an X-Response-Time header' | |
def __init__(self, app): | |
self.app = app | |
def start_response(self, default, start_time, status, headers): | |
headers = headers[:] + [('X-Response-Time', time.time() - start_time)] | |
return default(status, headers) | |
def __call__(self, environ, start_response): | |
return self.app(environ, functools.partial( | |
self.start_response, start_response, time.time())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment