Only parse requests and responses as msgpack if they were not JSON

pull/118/head
alufers 11 months ago
parent dcf1bd7694
commit b4f301f44c

@ -242,12 +242,13 @@ def main(override_args: Optional[Sequence[str]] = None):
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
pass pass
# try to parse the body as msgpack # try to parse the body as msgpack, if it's not json
try: if body_val is None:
body_val = msgpack.loads(req.get_request_body()) try:
content_type = "application/msgpack" body_val = msgpack.loads(req.get_request_body())
except Exception: content_type = "application/msgpack"
pass except Exception:
pass
if content_type is None: if content_type is None:
# try to parse the body as form data # try to parse the body as form data
@ -298,12 +299,13 @@ def main(override_args: Optional[Sequence[str]] = None):
except json.decoder.JSONDecodeError: except json.decoder.JSONDecodeError:
response_parsed = None response_parsed = None
# try parsing the response as msgpack if response_parsed is None:
try: # try parsing the response as msgpack, if it's not json
response_parsed = msgpack.loads(response_body) try:
response_content_type = "application/msgpack" response_parsed = msgpack.loads(response_body)
except Exception: response_content_type = "application/msgpack"
response_parsed = None except Exception:
response_parsed = None
if response_parsed is not None: if response_parsed is not None:
resp_data_to_set = { resp_data_to_set = {

Loading…
Cancel
Save