Skip to content

Instantly share code, notes, and snippets.

@teepark
Created April 19, 2010 03:45
Show Gist options
  • Save teepark/370730 to your computer and use it in GitHub Desktop.
Save teepark/370730 to your computer and use it in GitHub Desktop.
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