Skip to content

Instantly share code, notes, and snippets.

@bloodearnest
Last active May 9, 2016 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bloodearnest/39e980cce089c9ab058ecc4faee03b11 to your computer and use it in GitHub Desktop.
Save bloodearnest/39e980cce089c9ab058ecc4faee03b11 to your computer and use it in GitHub Desktop.
# standard wsgi middleware
def some_wsgi_middleware(app):
def middleware(environ, start_response)
# here's the trick - set status/headers in the function scope
status = headers = None
def custom_start_response(status, headers, exc_info):
# they get overwritten here from func args
pass
response = app(environ, custom_start_response)
if status == '404':
start_response('200', [])
return 'something something
else:
start_response(status, headers)
return response
return middleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment