diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-02-24 19:05:20 +0000 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2015-03-12 16:24:50 +0000 |
commit | c53ec53d80a02a1feea5efab18f0f84a0bdf4be8 (patch) | |
tree | e751b486b1f7a9530791c0d2ea2eaed19495dd40 | |
parent | Initial attempt at sprinkling some @metrics.counted decorations around the fe... (diff) | |
download | synapse-c53ec53d80a02a1feea5efab18f0f84a0bdf4be8.tar.xz |
Pull out all uses of the underlying HTTP user agent .request() method into a single wrapper function, to make adding metrics easier
-rw-r--r-- | synapse/http/client.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/synapse/http/client.py b/synapse/http/client.py index b53a07aa2d..d61e53bd94 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -45,12 +45,17 @@ class SimpleHttpClient(object): self.agent = Agent(reactor) self.version_string = hs.version_string + def request(self, method, *args, **kwargs): + # A small wrapper around self.agent.request() so we can easily attach + # counters to it + return self.agent.request(method, *args, **kwargs) + @defer.inlineCallbacks def post_urlencoded_get_json(self, uri, args={}): logger.debug("post_urlencoded_get_json args: %s", args) query_bytes = urllib.urlencode(args, True) - response = yield self.agent.request( + response = yield self.request( "POST", uri.encode("ascii"), headers=Headers({ @@ -70,7 +75,7 @@ class SimpleHttpClient(object): logger.info("HTTP POST %s -> %s", json_str, uri) - response = yield self.agent.request( + response = yield self.request( "POST", uri.encode("ascii"), headers=Headers({ @@ -104,7 +109,7 @@ class SimpleHttpClient(object): query_bytes = urllib.urlencode(args, True) uri = "%s?%s" % (uri, query_bytes) - response = yield self.agent.request( + response = yield self.request( "GET", uri.encode("ascii"), headers=Headers({ @@ -145,7 +150,7 @@ class SimpleHttpClient(object): json_str = encode_canonical_json(json_body) - response = yield self.agent.request( + response = yield self.request( "PUT", uri.encode("ascii"), headers=Headers({ @@ -176,7 +181,7 @@ class CaptchaServerHttpClient(SimpleHttpClient): def post_urlencoded_get_raw(self, url, args={}): query_bytes = urllib.urlencode(args, True) - response = yield self.agent.request( + response = yield self.request( "POST", url.encode("ascii"), bodyProducer=FileBodyProducer(StringIO(query_bytes)), |