diff options
| author | 2019-09-11 15:28:13 +0100 | |
|---|---|---|
| committer | 2019-09-11 15:28:13 +0100 | |
| commit | 8f8cf92ae22c2c30ef5e8b868691837afba25387 (patch) | |
| tree | edd5467db1a2fbed631cdd1dda23af773bbe8ff0 /src/utils | |
| parent | make context/conversation a "valid" URI (diff) | |
| signature | ||
automatically decode certain http content types
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/http.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/utils/http.py b/src/utils/http.py index 9459dcc0..5b5f36bb 100644 --- a/src/utils/http.py +++ b/src/utils/http.py @@ -34,6 +34,7 @@ USER_AGENT = ("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 " RESPONSE_MAX = (1024*1024)*100 SOUP_CONTENT_TYPES = ["text/html", "text/xml", "application/xml"] +DECODE_CONTENT_TYPES = ["text/plain"]+SOUP_CONTENT_TYPES class HTTPException(Exception): pass @@ -145,7 +146,11 @@ def request(url: str, method: str="GET", get_params: dict={}, except _json.decoder.JSONDecodeError as e: raise HTTPParsingException(str(e), data) - return Response(response.status_code, response_content, response_headers) + if content_type in DECODE_CONTENT_TYPES: + return Response(response.status_code, _decode_data(), response_headers) + else: + return Response(response.status_code, response_content, + response_headers) def request_many(urls: typing.List[str]) -> typing.Dict[str, Response]: responses = {} |
