summary refs log tree commit diff
path: root/synapse/http
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-01-29 14:55:27 +0000
committerMark Haines <mark.haines@matrix.org>2015-01-29 14:55:27 +0000
commit9d8f798a3fa0a0a98626218ff1602bf06be0fb82 (patch)
tree7226008bc691b4599c2c499de63c4bbced486a1b /synapse/http
parentMove bump schema delta (diff)
parentSYN-252: Supply the stream and topological parts in the correct order to the ... (diff)
downloadsynapse-9d8f798a3fa0a0a98626218ff1602bf06be0fb82.tar.xz
Merge changes from develop
Diffstat (limited to 'synapse/http')
-rw-r--r--synapse/http/client.py19
-rw-r--r--synapse/http/server.py8
2 files changed, 21 insertions, 6 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py
index 7793bab106..198f575cfa 100644
--- a/synapse/http/client.py
+++ b/synapse/http/client.py
@@ -63,6 +63,25 @@ class SimpleHttpClient(object):
         defer.returnValue(json.loads(body))
 
     @defer.inlineCallbacks
+    def post_json_get_json(self, uri, post_json):
+        json_str = json.dumps(post_json)
+
+        logger.info("HTTP POST %s -> %s", json_str, uri)
+
+        response = yield self.agent.request(
+            "POST",
+            uri.encode("ascii"),
+            headers=Headers({
+                "Content-Type": ["application/json"]
+            }),
+            bodyProducer=FileBodyProducer(StringIO(json_str))
+        )
+
+        body = yield readBody(response)
+
+        defer.returnValue(json.loads(body))
+
+    @defer.inlineCallbacks
     def get_json(self, uri, args={}):
         """ Get's some json from the given host and path
 
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 8015a22edf..0f6539e1be 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -16,7 +16,7 @@
 
 from synapse.http.agent_name import AGENT_NAME
 from synapse.api.errors import (
-    cs_exception, SynapseError, CodeMessageException
+    cs_exception, SynapseError, CodeMessageException, UnrecognizedRequestError
 )
 from synapse.util.logcontext import LoggingContext
 
@@ -139,11 +139,7 @@ class JsonResource(HttpServer, resource.Resource):
                     return
 
             # Huh. No one wanted to handle that? Fiiiiiine. Send 400.
-            self._send_response(
-                request,
-                400,
-                {"error": "Unrecognized request"}
-            )
+            raise UnrecognizedRequestError()
         except CodeMessageException as e:
             if isinstance(e, SynapseError):
                 logger.info("%s SynapseError: %s - %s", request, e.code, e.msg)