Skip to content

Commit 13fd579

Browse files
Merge pull request #3 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
2 parents b21652e + deab8a5 commit 13fd579

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

stats/miniclient.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ def http_get(host, port = 80, document = "/"):
5151
if "Content-Length" in headers:
5252
content_length = headers["Content-Length"]
5353
body = http.read()
54-
elif headers["Transfer-Encoding"] == "chunked":
54+
elif "Transfer-Encoding" in headers and headers["Transfer-Encoding"] == "chunked":
5555
while 1:
5656
chunk_length = int(http.readline(), 16)
5757
if chunk_length != 0:
5858
body += http.read(chunk_length)
5959
http.readline() # CRLF
6060
if chunk_length == 0:
6161
break
62+
else:
63+
# No Content-Length nor Transfer-Encoding header. Read until EOF
64+
body = http.read()
65+
6266
http.shutdown() # be nice, tell the http server we're done sending the request
6367
http.close() # all done
6468
return body
@@ -123,14 +127,18 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""):
123127
if "Content-Length" in headers:
124128
content_length = headers["Content-Length"]
125129
body = http.read()
126-
elif headers["Transfer-Encoding"] == "chunked":
130+
elif "Transfer-Encoding" in headers and headers["Transfer-Encoding"] == "chunked":
127131
while 1:
128132
chunk_length = int(http.readline(), 16)
129133
if chunk_length != 0:
130134
body += http.read(chunk_length)
131135
http.readline() # CRLF
132136
if chunk_length == 0:
133137
break
138+
else:
139+
# No Content-Length nor Transfer-Encoding header. Read until EOF
140+
body = http.read()
141+
134142
http.shutdown() # be nice, tell the http server we're done sending the request
135143
http.close() # all done
136144
return body

0 commit comments

Comments
 (0)