summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorMark Haines <mjark@negativecurvature.net>2016-03-11 17:27:37 +0000
committerMark Haines <mjark@negativecurvature.net>2016-03-11 17:27:37 +0000
commitffb9dd02feaeef7766c603952bc382ca1e75dcca (patch)
tree792ef6135a1a1a52f39a83a8e2ff6e2e28e949c7 /synapse/http
parentFix SQL statement (diff)
parentUse parse_json_object_from_request to parse JSON out of request bodies (diff)
downloadsynapse-ffb9dd02feaeef7766c603952bc382ca1e75dcca.tar.xz
Merge pull request #643 from matrix-org/markjh/parse_json_II
Use parse_json_object_from_request to parse JSON out of request bodies
Diffstat (limited to 'synapse/http')
-rw-r--r--synapse/http/servlet.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py
index 41c519c000..1996f8b136 100644
--- a/synapse/http/servlet.py
+++ b/synapse/http/servlet.py
@@ -128,14 +128,21 @@ def parse_json_object_from_request(request):
             if it wasn't a JSON object.
     """
     try:
-        content = simplejson.loads(request.content.read())
-        if type(content) != dict:
-            message = "Content must be a JSON object."
-            raise SynapseError(400, message, errcode=Codes.BAD_JSON)
-        return content
+        content_bytes = request.content.read()
+    except:
+        raise SynapseError(400, "Error reading JSON content.")
+
+    try:
+        content = simplejson.loads(content_bytes)
     except simplejson.JSONDecodeError:
         raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON)
 
+    if type(content) != dict:
+        message = "Content must be a JSON object."
+        raise SynapseError(400, message, errcode=Codes.BAD_JSON)
+
+    return content
+
 
 class RestServlet(object):