summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2014-12-02 15:09:51 +0000
committerMark Haines <mark.haines@matrix.org>2014-12-02 17:13:14 +0000
commit279c48c8b442ec726fb5088e56ce9c1d2ed4bfb5 (patch)
tree197c75f38f0059d2c99b5846f07839e41693ae92 /synapse/http/server.py
parentDrop log level for incorrect logging contexts to WARN if the context is wrong... (diff)
downloadsynapse-279c48c8b442ec726fb5088e56ce9c1d2ed4bfb5.tar.xz
Write the upload portion of version 1 of the media repository
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 8024ff5bde..046e230361 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -166,14 +166,10 @@ class JsonResource(HttpServer, resource.Resource):
                 request)
             return
 
-        if not self._request_user_agent_is_curl(request):
-            json_bytes = encode_canonical_json(response_json_object)
-        else:
-            json_bytes = encode_pretty_printed_json(response_json_object)
-
         # TODO: Only enable CORS for the requests that need it.
-        respond_with_json_bytes(request, code, json_bytes, send_cors=True,
-                                response_code_message=response_code_message)
+        respond_with_json(request, code, response_json_object, send_cors=True,
+                          response_code_message=response_code_message,
+                          pretty_print=self._request_user_agent_is_curl)
 
     @staticmethod
     def _request_user_agent_is_curl(request):
@@ -202,6 +198,17 @@ class RootRedirect(resource.Resource):
         return resource.Resource.getChild(self, name, request)
 
 
+def respond_with_json(request, code, json_object, send_cors=False,
+                      response_code_message=None, pretty_print=False):
+    if not pretty_print:
+        json_bytes = encode_pretty_printed_json(response_json_object)
+    else:
+        json_bytes = encode_canonical_json(response_json_object)
+
+    return respond_with_json_bytes(request, code, json_bytes, send_cors,
+                                   response_code_message=response_code_message)
+
+
 def respond_with_json_bytes(request, code, json_bytes, send_cors=False,
                             response_code_message=None):
     """Sends encoded JSON in response to the given request.