Skip to content

Instantly share code, notes, and snippets.

@1stvamp
Forked from bloodearnest/wsgi_extract.py
Last active May 9, 2016 14:40
Show Gist options
  • Save 1stvamp/a242c746646fa15195d8bc5a67c9a43c to your computer and use it in GitHub Desktop.
Save 1stvamp/a242c746646fa15195d8bc5a67c9a43c 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
response = app(environ, custom_start_response)
status = getattr(custom_start_response, '_status', '')
headers = getattr(custom_start_response, '_headers', {})
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