From deab8a57e81b48730b1fd4e270a6b778c65a84d0 Mon Sep 17 00:00:00 2001 From: Leonard Jonathan Oh Date: Sat, 21 Jan 2023 09:43:16 +0000 Subject: [PATCH] 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. --- stats/miniclient.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/stats/miniclient.py b/stats/miniclient.py index c97ff06..f746e7b 100644 --- a/stats/miniclient.py +++ b/stats/miniclient.py @@ -51,7 +51,7 @@ 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: @@ -59,6 +59,10 @@ def http_get(host, port = 80, document = "/"): 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 @@ -123,7 +127,7 @@ 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: @@ -131,6 +135,10 @@ def http_postSnapshot(host, port = 80, document = "/", snapshot = ""): 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