From a64bdac6767607968c50d0859dc10e6a3ec406b4 Mon Sep 17 00:00:00 2001 From: sjsullivan7 Date: Wed, 17 Oct 2018 22:38:55 -0400 Subject: [PATCH] Resolves ISSUE #5 Added new method to index.py to fix an issue with chunked encoding and missing request bodies Signed-off-by: Stephen Sullivan --- template/python27-flask/index.py | 12 ++++++++++++ template/python3-flask-armhf/index.py | 12 ++++++++++++ template/python3-flask/index.py | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/template/python27-flask/index.py b/template/python27-flask/index.py index 9b99405..983ef34 100644 --- a/template/python27-flask/index.py +++ b/template/python27-flask/index.py @@ -6,6 +6,18 @@ app = Flask(__name__) +@app.before_request +def fix_transfer_encoding(): + """ + Sets the "wsgi.input_terminated" environment flag, thus enabling + Werkzeug to pass chunked requests as streams. The gunicorn server + should set this, but it's not yet been implemented. + """ + + transfer_encoding = request.headers.get("Transfer-Encoding", None) + if transfer_encoding == u"chunked": + request.environ["wsgi.input_terminated"] = True + @app.route("/", defaults={"path": ""}, methods=["POST", "GET"]) @app.route("/", methods=["POST", "GET"]) def main_route(path): diff --git a/template/python3-flask-armhf/index.py b/template/python3-flask-armhf/index.py index bc9ac57..c7c785f 100644 --- a/template/python3-flask-armhf/index.py +++ b/template/python3-flask-armhf/index.py @@ -8,6 +8,18 @@ app = Flask(__name__) +@app.before_request +def fix_transfer_encoding(): + """ + Sets the "wsgi.input_terminated" environment flag, thus enabling + Werkzeug to pass chunked requests as streams. The gunicorn server + should set this, but it's not yet been implemented. + """ + + transfer_encoding = request.headers.get("Transfer-Encoding", None) + if transfer_encoding == u"chunked": + request.environ["wsgi.input_terminated"] = True + @app.route("/", defaults={"path": ""}, methods=["POST", "GET"]) @app.route("/", methods=["POST", "GET"]) def main_route(path): diff --git a/template/python3-flask/index.py b/template/python3-flask/index.py index bc9ac57..c7c785f 100644 --- a/template/python3-flask/index.py +++ b/template/python3-flask/index.py @@ -8,6 +8,18 @@ app = Flask(__name__) +@app.before_request +def fix_transfer_encoding(): + """ + Sets the "wsgi.input_terminated" environment flag, thus enabling + Werkzeug to pass chunked requests as streams. The gunicorn server + should set this, but it's not yet been implemented. + """ + + transfer_encoding = request.headers.get("Transfer-Encoding", None) + if transfer_encoding == u"chunked": + request.environ["wsgi.input_terminated"] = True + @app.route("/", defaults={"path": ""}, methods=["POST", "GET"]) @app.route("/", methods=["POST", "GET"]) def main_route(path):