esim/http_json_api.py: support text/plain response Content-Type

Allow returning text/plain Content-Types as 'data' output argument.

So far, all the esim/http_json_api functions require a JSON response.
However, a specific vendor has a list function where the request is JSON
but the response is text/plain CSV data. Allow and return in a dict.

Change-Id: Iba6e4cef1048b376050a435a900c0f395655a790
This commit is contained in:
Neels Hofmeyr
2026-02-20 02:09:51 +01:00
parent efc3f06f38
commit a4b5841f78

View File

@@ -256,5 +256,10 @@ class JsonHttpApiFunction(abc.ABC):
raise HttpHeaderError(response) raise HttpHeaderError(response)
if response.content: if response.content:
if response.headers.get('Content-Type').startswith('application/json'):
return self.decode(response.json()) return self.decode(response.json())
elif response.headers.get('Content-Type').startswith('text/plain;charset=UTF-8'):
return { 'data': response.content.decode('utf-8') }
raise HttpHeaderError(f'unimplemented response Content-Type: {response.headers=!r}')
return None return None