From 135569cf505636e0d6cb066e0338081b4acaf808 Mon Sep 17 00:00:00 2001 From: Tor Colvin Date: Wed, 10 Apr 2024 18:34:44 -0400 Subject: [PATCH] [3.1.5 backport] CBG-3887 add Content-Length header (#6769) --- tools-tests/upload_test.py | 8 +++++++- tools/tasks.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools-tests/upload_test.py b/tools-tests/upload_test.py index a3eff7144d..e79487ce0e 100644 --- a/tools-tests/upload_test.py +++ b/tools-tests/upload_test.py @@ -210,10 +210,16 @@ def test_stream_file(tmpdir, httpserver): p = tmpdir.join("testfile.txt") body = "foobar" p.write(body) + r = None def handler(request): - assert request.data == body.encode() + nonlocal r + r = request httpserver.expect_request("/").respond_with_handler(handler) assert tasks.do_upload(p, httpserver.url_for("/"), "") == 0 httpserver.check() + + assert r.headers.get("Content-Length") == '6' + assert r.headers.get("Transfer-Encoding") is None + assert r.data == body.encode() diff --git a/tools/tasks.py b/tools/tasks.py index de30821d9b..077f23b098 100644 --- a/tools/tasks.py +++ b/tools/tasks.py @@ -1081,6 +1081,7 @@ def do_upload(path, url, proxy): opener = urllib.request.build_opener(proxy_handler) request = urllib.request.Request(url, data=f, method='PUT') request.add_header(str('Content-Type'), str('application/zip')) + request.add_header('Content-Length', os.fstat(f.fileno()).st_size) exit_code = 0 try: