From ede8c18a5cb70257de3c06afa7816abc7eea23ed Mon Sep 17 00:00:00 2001 From: Tom Kirby-Green Date: Fri, 5 Nov 2021 16:16:14 +0000 Subject: [PATCH] Respect content-type with charset When deciding how to un-marshall a response from an auth request, the logic excludes Content-Type values that affix a charset value to the end of the string (eg: application/json; charset=utf-8). This PR is an evolution of @jvinet 's contribution. Thank you for that Judd. --- ably/http/http.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ably/http/http.py b/ably/http/http.py index 062af134..278810d4 100644 --- a/ably/http/http.py +++ b/ably/http/http.py @@ -92,12 +92,13 @@ def to_native(self): return None content_type = self.__response.headers.get('content-type') - if content_type == 'application/x-msgpack': - return msgpack.unpackb(content) - elif content_type == 'application/json': - return self.__response.json() - else: - raise ValueError("Unsupported content type") + if isinstance(content_type, str): + if content_type.startswith('application/x-msgpack'): + return msgpack.unpackb(content) + elif content_type.startswith('application/json'): + return self.__response.json() + + raise ValueError("Unsupported content type") @property def response(self):