diff options
| author | Nejc Habjan <nejc.habjan@siemens.com> | 2023-03-12 17:28:15 +0100 |
|---|---|---|
| committer | John Villalovos <john@sodarock.com> | 2023-03-12 10:09:58 -0700 |
| commit | 76063c386ef9caf84ba866515cb053f6129714d9 (patch) | |
| tree | 81f537fba41cbea21ffa69de3c32d581d1e0256d /gitlab | |
| parent | 90f96acf9e649de9874cec612fc1b49c4a843447 (diff) | |
| download | gitlab-76063c386ef9caf84ba866515cb053f6129714d9.tar.gz | |
fix(client): properly parse content-type when charset is present
Diffstat (limited to 'gitlab')
| -rw-r--r-- | gitlab/client.py | 11 | ||||
| -rw-r--r-- | gitlab/utils.py | 8 |
2 files changed, 13 insertions, 6 deletions
diff --git a/gitlab/client.py b/gitlab/client.py index 495ed44..94fb66a 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -828,12 +828,9 @@ class Gitlab: result = self.http_request( "get", path, query_data=query_data, streamed=streamed, **kwargs ) + content_type = utils.get_content_type(result.headers.get("Content-Type")) - if ( - result.headers["Content-Type"] == "application/json" - and not streamed - and not raw - ): + if content_type == "application/json" and not streamed and not raw: try: json_result = result.json() if TYPE_CHECKING: @@ -1030,8 +1027,10 @@ class Gitlab: raw=raw, **kwargs, ) + content_type = utils.get_content_type(result.headers.get("Content-Type")) + try: - if result.headers.get("Content-Type", None) == "application/json": + if content_type == "application/json": json_result = result.json() if TYPE_CHECKING: assert isinstance(json_result, dict) diff --git a/gitlab/utils.py b/gitlab/utils.py index 9317535..5170b18 100644 --- a/gitlab/utils.py +++ b/gitlab/utils.py @@ -1,3 +1,4 @@ +import email.message import pathlib import traceback import urllib.parse @@ -14,6 +15,13 @@ class _StdoutStream: print(chunk) +def get_content_type(content_type: Optional[str]) -> str: + message = email.message.Message() + message["content-type"] = content_type + + return message.get_content_type() + + def response_content( response: requests.Response, streamed: bool, |
