From dd0e2df4fdc11d72203c5e4b1f4bdf4ec5f11655 Mon Sep 17 00:00:00 2001 From: Diogo Martins Date: Fri, 10 Jul 2026 15:44:29 +0100 Subject: [PATCH] GunicornServer: read chunked request bodies in the WSGI app MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The app read the POST body via CONTENT_LENGTH only; a chunked request has no Content-Length, so it read 0 bytes — the /echo-style body came back empty and chunk framing was never decoded, making Gunicorn fail every chunked test despite its sync worker supporting chunked. Now: on Transfer-Encoding, read wsgi.input to EOF (Gunicorn dechunks) and 400 on a decode error; the Content-Length path is unchanged. --- src/Servers/GunicornServer/app.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Servers/GunicornServer/app.py b/src/Servers/GunicornServer/app.py index b9feb99..4646dfb 100644 --- a/src/Servers/GunicornServer/app.py +++ b/src/Servers/GunicornServer/app.py @@ -27,12 +27,21 @@ def app(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) return [body] - start_response('200 OK', [('Content-Type', 'text/plain')]) if environ['REQUEST_METHOD'] == 'POST': - try: - length = int(environ.get('CONTENT_LENGTH', 0) or 0) - except ValueError: - length = 0 - body = environ['wsgi.input'].read(length) if length > 0 else b'' + if environ.get('HTTP_TRANSFER_ENCODING'): + # chunked request: no Content-Length; Gunicorn's worker dechunks, so read to EOF + try: + body = environ['wsgi.input'].read() + except Exception: + start_response('400 Bad Request', [('Content-Type', 'text/plain')]) + return [b''] + else: + try: + length = int(environ.get('CONTENT_LENGTH', 0) or 0) + except ValueError: + length = 0 + body = environ['wsgi.input'].read(length) if length > 0 else b'' + start_response('200 OK', [('Content-Type', 'text/plain')]) return [body] + start_response('200 OK', [('Content-Type', 'text/plain')]) return [b'OK']