Skip to content

Commit deab8a5

Browse files
committed
Fix (python): Fix regression in miniclient.http_get() to read full response body if Content-Length or Transfer-Encoding HTTP Headers are absent
This fixes a critical regression that causes the BF2 server to not process stats if the ASP webserver does not respond with `Content-Length` or `Transfer-Encoding` HTTP Headers. Fixes regression in #2.
1 parent b21652e commit deab8a5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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)