aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-04 13:47:03 +0100
committerGravatar jesopo2019-06-04 13:47:03 +0100
commita802e66dcfee1bb83e76095024fc9fbc06cf9c16 (patch)
tree94e18f76acb64aca04765a712e2ca36ff8009d59 /src
parent'hunder2' -> 'hunter2'. meme typos D: (diff)
signature
Defer decoding http payload bytestring until after checking ContentType
Diffstat (limited to 'src')
-rw-r--r--src/utils/http.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/utils/http.py b/src/utils/http.py
index 2d7c512a..b9379344 100644
--- a/src/utils/http.py
+++ b/src/utils/http.py
@@ -64,17 +64,20 @@ def request(url: str, method: str="GET", get_params: dict={},
signal.signal(signal.SIGALRM, signal.SIG_IGN)
response_headers = utils.CaseInsensitiveDict(dict(response.headers))
- data = response_content.decode(response.encoding or fallback_encoding)
content_type = response.headers["Content-Type"].split(";", 1)[0]
+ def _decode_data():
+ return response_content.decode(response.encoding or fallback_encoding)
+
if soup:
if content_type in SOUP_CONTENT_TYPES:
- soup = bs4.BeautifulSoup(data, parser)
+ soup = bs4.BeautifulSoup(_decode_data(), parser)
return Response(response.status_code, soup, response_headers)
else:
raise HTTPWrongContentTypeException(
"Tried to soup non-html/non-xml data")
+ data = _decode_data()
if json and data:
try:
return Response(response.status_code, _json.loads(data),