summary refs log tree commit diff
path: root/synapse/http/server.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-06-01 10:56:05 +0100
committerMark Haines <mark.haines@matrix.org>2015-06-01 10:56:05 +0100
commitb8d49be5a1d8719ec47a44547d043874c8bfaddc (patch)
tree52e58244f968f10176f8624eac19452d3337f810 /synapse/http/server.py
parentUse Twisted-15.2.1, Use Agent.usingEndpointFactory rather than implement our ... (diff)
parentMerge pull request #172 from intelfx/contrib-systemd (diff)
downloadsynapse-b8d49be5a1d8719ec47a44547d043874c8bfaddc.tar.xz
Merge branch 'develop' into markjh/twisted-15
Conflicts:
	synapse/python_dependencies.py
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r--synapse/http/server.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 73efbff4f2..ae8f3b3972 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -19,9 +19,10 @@ from synapse.api.errors import (
 )
 from synapse.util.logcontext import LoggingContext, PreserveLoggingContext
 import synapse.metrics
+import synapse.events
 
 from syutil.jsonutil import (
-    encode_canonical_json, encode_pretty_printed_json
+    encode_canonical_json, encode_pretty_printed_json, encode_json
 )
 
 from twisted.internet import defer
@@ -168,9 +169,10 @@ class JsonResource(HttpServer, resource.Resource):
 
     _PathEntry = collections.namedtuple("_PathEntry", ["pattern", "callback"])
 
-    def __init__(self, hs):
+    def __init__(self, hs, canonical_json=True):
         resource.Resource.__init__(self)
 
+        self.canonical_json = canonical_json
         self.clock = hs.get_clock()
         self.path_regexs = {}
         self.version_string = hs.version_string
@@ -256,6 +258,7 @@ class JsonResource(HttpServer, resource.Resource):
             response_code_message=response_code_message,
             pretty_print=_request_user_agent_is_curl(request),
             version_string=self.version_string,
+            canonical_json=self.canonical_json,
         )
 
 
@@ -277,11 +280,16 @@ class RootRedirect(resource.Resource):
 
 def respond_with_json(request, code, json_object, send_cors=False,
                       response_code_message=None, pretty_print=False,
-                      version_string=""):
+                      version_string="", canonical_json=True):
     if pretty_print:
         json_bytes = encode_pretty_printed_json(json_object) + "\n"
     else:
-        json_bytes = encode_canonical_json(json_object)
+        if canonical_json:
+            json_bytes = encode_canonical_json(json_object)
+        else:
+            json_bytes = encode_json(
+                json_object, using_frozen_dicts=synapse.events.USE_FROZEN_DICTS
+            )
 
     return respond_with_json_bytes(
         request, code, json_bytes,