Skip to content

Commit

Permalink
Merge pull request #3 from startersclan/fix/python-fix-regression-in-…
Browse files Browse the repository at this point in the history
…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 authored Jan 21, 2023
2 parents b21652e + deab8a5 commit 13fd579
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions 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 13fd579

Please sign in to comment.