mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
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:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user