-
-
Save 1stvamp/a242c746646fa15195d8bc5a67c9a43c to your computer and use it in GitHub Desktop.
This file contains 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
# 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