From 77ee4d8fa264e1a5788a71a74a0fb4241808cb52 Mon Sep 17 00:00:00 2001 From: Pablo Ventura Date: Sun, 9 Aug 2026 23:16:39 -0300 Subject: [PATCH 1/2] requests: Match response header names case-insensitively. Signed-off-by: Pablo Ventura --- python-ecosys/requests/requests/__init__.py | 5 ++-- python-ecosys/requests/test_requests.py | 29 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/python-ecosys/requests/requests/__init__.py b/python-ecosys/requests/requests/__init__.py index 68f63d13c..14663055d 100644 --- a/python-ecosys/requests/requests/__init__.py +++ b/python-ecosys/requests/requests/__init__.py @@ -223,10 +223,11 @@ def request( if not l or l == b"\r\n": break # print(l) - if l.startswith(b"Transfer-Encoding:"): + lowerl = l.lower() + if lowerl.startswith(b"transfer-encoding:"): if b"chunked" in l: chunked = True - elif l.startswith(b"Location:") and not 200 <= status <= 299: + elif lowerl.startswith(b"location:") and not 200 <= status <= 299: if status in [301, 302, 303, 307, 308]: redirect = str(l[10:-2], "utf-8") if redirect.startswith("/"): diff --git a/python-ecosys/requests/test_requests.py b/python-ecosys/requests/test_requests.py index 38f5b8026..e40eb193f 100644 --- a/python-ecosys/requests/test_requests.py +++ b/python-ecosys/requests/test_requests.py @@ -332,6 +332,33 @@ def test_redirect_relative(): socket.socket = lambda *a, **k: Socket() +def test_chunked_response_lowercase_header(): + socket.socket = lambda *a, **k: Socket( + read_data=b"HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\n\r\n5\r\nhello\r\n6\r\n world\r\n0\r\n\r\n" + ) + response = requests.request("GET", "http://example.com") + assert response.content == b"hello world" + socket.socket = lambda *a, **k: Socket() + + +def test_redirect_lowercase_location(): + server = iter( + [ + b"HTTP/1.1 301 OK\r\nlocation: /index\r\n\r\n", + SERVER_RESPONSE_200_OK, + ] + ) + socket.socket = lambda *a, **k: Socket(next(server)) + + response = requests.request("GET", "http://example.com") + + assert response.raw._write_buffer.getvalue() == ( + b"GET /index HTTP/1.1\r\nConnection: close\r\nHost: example.com\r\n\r\n" + ), format_message(response) + + socket.socket = lambda *a, **k: Socket() + + test_simple_get() test_get_query_anchor() test_get_auth() @@ -354,3 +381,5 @@ def test_redirect_relative(): test_raw_readinto_content_length() test_redirect_absolute() test_redirect_relative() +test_chunked_response_lowercase_header() +test_redirect_lowercase_location() From 3eefac805e08d77d4ceada224d8bf280479f10e3 Mon Sep 17 00:00:00 2001 From: Pablo Ventura Date: Fri, 14 Aug 2026 12:13:09 -0300 Subject: [PATCH 2/2] requests: Reuse lowerl for Content-Length matching. Signed-off-by: Pablo Ventura --- python-ecosys/requests/manifest.py | 2 +- python-ecosys/requests/requests/__init__.py | 2 +- python-ecosys/requests/test_requests.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/python-ecosys/requests/manifest.py b/python-ecosys/requests/manifest.py index b49ae557e..cbb311fbd 100644 --- a/python-ecosys/requests/manifest.py +++ b/python-ecosys/requests/manifest.py @@ -1,3 +1,3 @@ -metadata(version="1.1.0", pypi="requests") +metadata(version="1.1.1", pypi="requests") package("requests") diff --git a/python-ecosys/requests/requests/__init__.py b/python-ecosys/requests/requests/__init__.py index 14663055d..b0e479ead 100644 --- a/python-ecosys/requests/requests/__init__.py +++ b/python-ecosys/requests/requests/__init__.py @@ -241,7 +241,7 @@ def request( k, v = l.split(":", 1) v = v.strip() resp_d[k] = v - if k.lower() == "content-length": + if lowerl.startswith(b"content-length:"): remaining = int(v) else: parse_headers(l, resp_d) diff --git a/python-ecosys/requests/test_requests.py b/python-ecosys/requests/test_requests.py index e40eb193f..c12589c02 100644 --- a/python-ecosys/requests/test_requests.py +++ b/python-ecosys/requests/test_requests.py @@ -359,6 +359,16 @@ def test_redirect_lowercase_location(): socket.socket = lambda *a, **k: Socket() +def test_content_length_lowercase_header(): + socket.socket = lambda *a, **k: Socket( + read_data=b"HTTP/1.1 200 OK\r\ncontent-length: 5\r\n\r\nhello" + ) + response = requests.request("GET", "http://example.com") + assert response.content == b"hello" + assert response.headers["content-length"] == "5" + socket.socket = lambda *a, **k: Socket() + + test_simple_get() test_get_query_anchor() test_get_auth() @@ -383,3 +393,4 @@ def test_redirect_lowercase_location(): test_redirect_relative() test_chunked_response_lowercase_header() test_redirect_lowercase_location() +test_content_length_lowercase_header()