Skip to content

Commit

Permalink
Backport: Cherry-pick from merge commit d5ad894
Browse files Browse the repository at this point in the history
Merge pull request #91 from startersclan/fix/python-fix-regression-in-miniclient.http-get-to-read-full-response-body-if-content-length-or-transfer-encoding-http-headers-are-absent

Fix (python): Fix regression in `miniclient.http_get()` to read full response body if `Content-Length` or `Transfer-Encoding` HTTP Headers are absent
  • Loading branch information
leojonathanoh committed Jan 21, 2023
1 parent f2d666b commit 380d5c5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/python/bf2/stats/miniclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ def http_get(host, port = 80, document = "/"):
if "Content-Length" in headers:
content_length = headers["Content-Length"]
body = http.read()
elif headers["Transfer-Encoding"] == "chunked":
elif "Transfer-Encoding" in headers and headers["Transfer-Encoding"] == "chunked":
while 1:
chunk_length = int(http.readline(), 16)
if chunk_length != 0:
body += http.read(chunk_length)
http.readline() # CRLF
if chunk_length == 0:
break
else:
# No Content-Length nor Transfer-Encoding header. Read until EOF
body = http.read()

http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
return body
Expand Down Expand Up @@ -123,14 +127,18 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
if "Content-Length" in headers:
content_length = headers["Content-Length"]
body = http.read()
elif headers["Transfer-Encoding"] == "chunked":
elif "Transfer-Encoding" in headers and headers["Transfer-Encoding"] == "chunked":
while 1:
chunk_length = int(http.readline(), 16)
if chunk_length != 0:
body += http.read(chunk_length)
http.readline() # CRLF
if chunk_length == 0:
break
else:
# No Content-Length nor Transfer-Encoding header. Read until EOF
body = http.read()

http.shutdown() # be nice, tell the http server we're done sending the request
http.close() # all done
return body
Expand Down

0 comments on commit 380d5c5

Please sign in to comment.