Skip to content

Instantly share code, notes, and snippets.

@1stvamp
Created May 9, 2016 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1stvamp/7dcccb8e8a96c34010edf71053ac822d to your computer and use it in GitHub Desktop.
Save 1stvamp/7dcccb8e8a96c34010edf71053ac822d to your computer and use it in GitHub Desktop.
# standard wsgi middleware
def some_wsgi_middleware(app):
def middleware(environ, start_response)
def custom_start_response(status, headers, exc_info):
# they get overwritten here from func args
custom_start_response._status = status
custom_start_response._headers = headers
custom_start_response._status = custom_start_response._headers = None
response = app(environ, custom_start_response)
if custom_start_response._status == '404':
start_response('200', [])
return 'something something'
else:
start_response(custom_start_response._status, custom_start_response._headers)
return response
return middleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment