Created
November 1, 2023 14:37
-
-
Save wrkhenddher/f96423b6631388868c02d8f68159108e to your computer and use it in GitHub Desktop.
Werkzeug LintMiddleware w/Flask
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
# Pretty much lifted from https://github.com/pallets/flask/issues/2992 | |
# | |
# To test: | |
# $ export FLASK_APP=flask_issue.py | |
# $ python -m flask run | |
# $ curl -v http://127.0.0.1:5000/streamingerror | |
# Notice how respose is 200 but still truncated | |
from flask import Flask, Response | |
from werkzeug.middleware.lint import LintMiddleware | |
app = Flask(__name__) | |
# Wire LintMiddleware | |
app.wsgi_app = LintMiddleware(app.wsgi_app) | |
@app.route('/') | |
def default_route(): | |
return 'hello world' | |
@app.route('/error') | |
def error_route(): | |
raise Exception('error in error_route') | |
@app.route('/streamingerror') | |
def streaming_error_route(): | |
def inner_gen(): | |
yield 'hello' | |
raise Exception('error from streaming_error_route') | |
yield 'bye' | |
return Response(inner_gen()) | |
@app.errorhandler(Exception) | |
def custom_exception_handler(_): | |
return 'handled by custom exception handler' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment