diff options
author | Erik Johnston <erik@matrix.org> | 2014-10-20 17:53:18 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-10-20 17:53:18 +0100 |
commit | 4ae0844ee3128cf4cfdcaf87216ba69f8eb1bf5d (patch) | |
tree | 4c40d64dcf344cbfe021d3349e83d2e236f4c49f /synapse/http/client.py | |
parent | more timestamp fixes (diff) | |
parent | use a tagged version of syutil rather than master (diff) | |
download | synapse-4ae0844ee3128cf4cfdcaf87216ba69f8eb1bf5d.tar.xz |
Merge branch 'master' of github.com:matrix-org/synapse into develop
Diffstat (limited to 'synapse/http/client.py')
-rw-r--r-- | synapse/http/client.py | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py index 316ca1ccb9..46c90dbb76 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -101,7 +101,9 @@ class BaseHttpClient(object): while True: - producer = body_callback(method, url_bytes, headers_dict) + producer = None + if body_callback: + producer = body_callback(method, url_bytes, headers_dict) try: response = yield self.agent.request( @@ -312,6 +314,42 @@ class IdentityServerHttpClient(BaseHttpClient): defer.returnValue(json.loads(body)) + @defer.inlineCallbacks + def get_json(self, destination, path, args={}, retry_on_dns_fail=True): + """ Get's some json from the given host homeserver and path + + Args: + destination (str): The remote server to send the HTTP request + to. + path (str): The HTTP path. + args (dict): A dictionary used to create query strings, defaults to + None. + **Note**: The value of each key is assumed to be an iterable + and *not* a string. + + Returns: + Deferred: Succeeds when we get *any* HTTP response. + + The result of the deferred is a tuple of `(code, response)`, + where `response` is a dict representing the decoded JSON body. + """ + logger.debug("get_json args: %s", args) + + query_bytes = urllib.urlencode(args, True) + logger.debug("Query bytes: %s Retry DNS: %s", args, retry_on_dns_fail) + + response = yield self._create_request( + destination.encode("ascii"), + "GET", + path.encode("ascii"), + query_bytes=query_bytes, + retry_on_dns_fail=retry_on_dns_fail, + body_callback=None + ) + + body = yield readBody(response) + + defer.returnValue(json.loads(body)) class CaptchaServerHttpClient(MatrixHttpClient): """Separate HTTP client for talking to google's captcha servers""" |