From 733150194ba191ea3121d0fe5ab3157649d8df24 Mon Sep 17 00:00:00 2001 From: "Paul J. Dorn" Date: Thu, 20 Mar 2025 22:42:15 +0100 Subject: [PATCH] stop pretending to support gzip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * https://peps.python.org/pep-3333/#other-http-features "WSGI servers must handle any supported inbound “hop-by-hop” headers on their own, such as by decoding any inbound Transfer-Encoding, including chunked encoding if applicable." * https://datatracker.ietf.org/doc/html/rfc9110#section-7.6.1 "intermediaries SHOULD remove or replace fields that are known to require removal before forwarding" * partial revert: 555d2fa27f2d891f23bd03890e4a826b5018c6b4 --- gunicorn/http/message.py | 5 ----- tests/requests/invalid/chunked_06.http | 2 +- tests/requests/valid/025.http | 2 +- tests/requests/valid/025.py | 2 +- tests/requests/valid/025_line.http | 2 +- tests/requests/valid/025_line.py | 2 +- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/gunicorn/http/message.py b/gunicorn/http/message.py index 59ce0bf4b..6c9c4b01c 100644 --- a/gunicorn/http/message.py +++ b/gunicorn/http/message.py @@ -190,11 +190,6 @@ def set_body_reader(self): # safe option: nuke it, its never needed if chunked: raise InvalidHeader("TRANSFER-ENCODING", req=self) - elif val.lower() in ('compress', 'deflate', 'gzip'): - # chunked should be the last one - if chunked: - raise InvalidHeader("TRANSFER-ENCODING", req=self) - self.force_close() else: raise UnsupportedTransferCoding(value) diff --git a/tests/requests/invalid/chunked_06.http b/tests/requests/invalid/chunked_06.http index ef70faab9..8d4aaa6e9 100644 --- a/tests/requests/invalid/chunked_06.http +++ b/tests/requests/invalid/chunked_06.http @@ -1,6 +1,6 @@ POST /chunked_not_last HTTP/1.1\r\n Transfer-Encoding: chunked\r\n -Transfer-Encoding: gzip\r\n +Transfer-Encoding: identity\r\n \r\n 5\r\n hello\r\n diff --git a/tests/requests/valid/025.http b/tests/requests/valid/025.http index e1cc2b580..fbd573a9d 100644 --- a/tests/requests/valid/025.http +++ b/tests/requests/valid/025.http @@ -1,5 +1,5 @@ POST /chunked HTTP/1.1\r\n -Transfer-Encoding: gzip\r\n +Transfer-Encoding: identity\r\n Transfer-Encoding: chunked\r\n \r\n 5\r\n diff --git a/tests/requests/valid/025.py b/tests/requests/valid/025.py index d23870680..eb97b6301 100644 --- a/tests/requests/valid/025.py +++ b/tests/requests/valid/025.py @@ -3,7 +3,7 @@ "uri": uri("/chunked"), "version": (1, 1), "headers": [ - ('TRANSFER-ENCODING', 'gzip'), + ('TRANSFER-ENCODING', 'identity'), ('TRANSFER-ENCODING', 'chunked') ], "body": b"hello world" diff --git a/tests/requests/valid/025_line.http b/tests/requests/valid/025_line.http index bde502671..b91863e3d 100644 --- a/tests/requests/valid/025_line.http +++ b/tests/requests/valid/025_line.http @@ -1,5 +1,5 @@ POST /chunked HTTP/1.1\r\n -Transfer-Encoding: gzip,chunked\r\n +Transfer-Encoding: identity,chunked\r\n \r\n 5\r\n hello\r\n diff --git a/tests/requests/valid/025_line.py b/tests/requests/valid/025_line.py index b2ebc652e..e7e9ad92c 100644 --- a/tests/requests/valid/025_line.py +++ b/tests/requests/valid/025_line.py @@ -3,7 +3,7 @@ "uri": uri("/chunked"), "version": (1, 1), "headers": [ - ('TRANSFER-ENCODING', 'gzip,chunked') + ('TRANSFER-ENCODING', 'identity,chunked') ], "body": b"hello world"