summary refs log tree commit diff
path: root/synapse/http/servlet.py
diff options
context:
space:
mode:
authorWill Hunt <will@half-shot.uk>2018-08-16 01:13:05 +0100
committerWill Hunt <will@half-shot.uk>2018-08-16 01:13:05 +0100
commitb3e005de18d8cc0d871f3f4f4bbfee4d2eca9c24 (patch)
treef2e43f102010ea827fd94e54c79f3036b53f9539 /synapse/http/servlet.py
parentisorted this mess (diff)
parentMerge pull request #3686 from matrix-org/rav/changelog_links_to_prs (diff)
downloadsynapse-b3e005de18d8cc0d871f3f4f4bbfee4d2eca9c24.tar.xz
Merge remote-tracking branch 'upstream/develop' into hs/upload-limits
Diffstat (limited to 'synapse/http/servlet.py')
-rw-r--r--synapse/http/servlet.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py

index 882816dc8f..69f7085291 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py
@@ -171,8 +171,16 @@ def parse_json_value_from_request(request, allow_empty_body=False): if not content_bytes and allow_empty_body: return None + # Decode to Unicode so that simplejson will return Unicode strings on + # Python 2 try: - content = json.loads(content_bytes) + content_unicode = content_bytes.decode('utf8') + except UnicodeDecodeError: + logger.warn("Unable to decode UTF-8") + raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON) + + try: + content = json.loads(content_unicode) except Exception as e: logger.warn("Unable to parse JSON: %s", e) raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)