Skip to content

Commit

Permalink
[3.1.5 backport] CBG-3887 add Content-Length header (#6769)
Browse files Browse the repository at this point in the history
  • Loading branch information
torcolvin authored Apr 10, 2024
1 parent edcd393 commit 135569c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tools-tests/upload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions tools/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 135569c

Please sign in to comment.