From 2e94212886e4c9531b8ba7f55f4fb0b8134e10ac Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 4 Aug 2017 19:40:45 -0400 Subject: [PATCH] chunked encoding Signed-off-by: Kenneth Reitz --- httpbin/core.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/httpbin/core.py b/httpbin/core.py index 67cb11c8..5c1caed5 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -42,12 +42,23 @@ '__utmb' ) + def jsonify(*args, **kwargs): response = flask_jsonify(*args, **kwargs) if not response.data.endswith(b'\n'): response.data += b'\n' return response + +class InputTerminated: + def __init__(self, wsgi_app): + self.wsgi_app = wsgi_app + + def __call__(self, environ, start_response): + environ['wsgi.input_terminated'] = True + return self.wsgi_app(environ, start_response) + + # Prevent WSGI from correcting the casing of the Location header BaseResponse.autocorrect_location_header = False @@ -57,6 +68,10 @@ def jsonify(*args, **kwargs): app = Flask(__name__, template_folder=tmpl_dir) app.debug = bool(os.environ.get('DEBUG')) +# Support for chunked-encoding. +app.wsgi_app = InputTerminated(app.wsgi_app) + + # Setup Flask-Common. common = Common(app)