diff options
author | Erik Johnston <erik@matrix.org> | 2018-11-30 14:39:26 +0000 |
---|---|---|
committer | Brendan Abolivier <babolivier@matrix.org> | 2019-02-13 15:16:05 +0000 |
commit | 561fa571c3dcaa1a2c183e9a93d85d6616978c4b (patch) | |
tree | 029128b60af779160ad4102138843c81e0600d32 | |
parent | Fix bug in DTG (diff) | |
download | synapse-561fa571c3dcaa1a2c183e9a93d85d6616978c4b.tar.xz |
Fix fetching media when using proxy
-rw-r--r-- | synapse/http/matrixfederationclient.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py index 729e6e9924..0edb91f960 100644 --- a/synapse/http/matrixfederationclient.py +++ b/synapse/http/matrixfederationclient.py @@ -216,6 +216,15 @@ class MatrixFederationHttpClient(object): self.agent = Agent.usingEndpointFactory( reactor, MatrixFederationEndpointFactory(hs), pool=pool ) + + file_pool = HTTPConnectionPool(reactor) + file_pool.retryAutomatically = False + file_pool.maxPersistentPerHost = 5 + file_pool.cachedConnectionTimeout = 10 + + self.file_agent = Agent.usingEndpointFactory( + reactor, MatrixFederationEndpointFactory(hs), pool=file_pool + ) self.clock = hs.get_clock() self._store = hs.get_datastore() self.version_string_bytes = hs.version_string.encode('ascii') @@ -238,6 +247,7 @@ class MatrixFederationHttpClient(object): ignore_backoff=False, backoff_on_404=False, span=None, + agent=None, ): """ Sends a request to the given server. @@ -357,9 +367,12 @@ class MatrixFederationHttpClient(object): for key, value in iteritems(carrier): headers_dict[key.encode("ascii")] = [value.encode("ascii")] + if not agent: + agent = self.agent + # we don't want all the fancy cookie and redirect handling that # treq.request gives: just use the raw Agent. - request_deferred = self.agent.request( + request_deferred = agent.request( method_bytes, url_bytes, headers=Headers(headers_dict), @@ -757,6 +770,7 @@ class MatrixFederationHttpClient(object): request, retry_on_dns_fail=retry_on_dns_fail, ignore_backoff=ignore_backoff, + agent=self.file_agent, ) headers = dict(response.headers.getAllRawHeaders()) |