summary refs log tree commit diff
path: root/synapse/http/client.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2014-09-05 19:18:23 -0700
committerKegan Dougal <kegan@matrix.org>2014-09-05 19:18:23 -0700
commit1829b55bb0d75d29475ac84eeb3e37cad8b334c7 (patch)
tree331df854248d9579fc2e4c91da09ab10423f910a /synapse/http/client.py
parentAdded a captcha config to the HS, to enable registration captcha checking and... (diff)
downloadsynapse-1829b55bb0d75d29475ac84eeb3e37cad8b334c7.tar.xz
Captchas now work on registration. Missing x-forwarded-for config arg support. Missing reloading a new captcha on the web client / displaying a sensible error message.
Diffstat (limited to 'synapse/http/client.py')
-rw-r--r--synapse/http/client.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py
index ebf1aa47c4..ece6318e00 100644
--- a/synapse/http/client.py
+++ b/synapse/http/client.py
@@ -16,7 +16,7 @@
 
 from twisted.internet import defer, reactor
 from twisted.internet.error import DNSLookupError
-from twisted.web.client import _AgentBase, _URI, readBody, FileBodyProducer
+from twisted.web.client import _AgentBase, _URI, readBody, FileBodyProducer, PartialDownloadError
 from twisted.web.http_headers import Headers
 
 from synapse.http.endpoint import matrix_endpoint
@@ -188,6 +188,32 @@ class TwistedHttpClient(HttpClient):
         body = yield readBody(response)
 
         defer.returnValue(json.loads(body))
+        
+    # XXX FIXME : I'm so sorry.
+    @defer.inlineCallbacks
+    def post_urlencoded_get_raw(self, destination, path, accept_partial=False, args={}):
+        if destination in _destination_mappings:
+            destination = _destination_mappings[destination]
+
+        query_bytes = urllib.urlencode(args, True)
+
+        response = yield self._create_request(
+            destination.encode("ascii"),
+            "POST",
+            path.encode("ascii"),
+            producer=FileBodyProducer(StringIO(urllib.urlencode(args))),
+            headers_dict={"Content-Type": ["application/x-www-form-urlencoded"]}
+        )
+
+        try:
+            body = yield readBody(response)
+            defer.returnValue(body)
+        except PartialDownloadError as e:
+            if accept_partial:
+                defer.returnValue(e.response)
+            else:
+                raise e
+        
 
     @defer.inlineCallbacks
     def _create_request(self, destination, method, path_bytes, param_bytes=b"",