Skip to content
Snippets Groups Projects
Commit 7c0295f1 authored by Andrew Morgan's avatar Andrew Morgan
Browse files

no kwargs today

parent 66cdb840
No related branches found
No related tags found
No related merge requests found
...@@ -193,7 +193,9 @@ class MatrixFederationHttpClient(object): ...@@ -193,7 +193,9 @@ class MatrixFederationHttpClient(object):
self, self,
request, request,
try_trailing_slash_on_400=False, try_trailing_slash_on_400=False,
**kwargs): backoff_on_404=False,
send_request_args={},
):
"""Wrapper for _send_request which can optionally retry the request """Wrapper for _send_request which can optionally retry the request
upon receiving a combination of a 400 HTTP response code and a upon receiving a combination of a 400 HTTP response code and a
'M_UNRECOGNIZED' errcode. This is a workaround for Synapse <=v0.99.2 'M_UNRECOGNIZED' errcode. This is a workaround for Synapse <=v0.99.2
...@@ -204,14 +206,17 @@ class MatrixFederationHttpClient(object): ...@@ -204,14 +206,17 @@ class MatrixFederationHttpClient(object):
try_trailing_slash_on_400 (bool): Whether on receiving a 400 try_trailing_slash_on_400 (bool): Whether on receiving a 400
'M_UNRECOGNIZED' from the server to retry the request with a 'M_UNRECOGNIZED' from the server to retry the request with a
trailing slash appended to the request path. trailing slash appended to the request path.
kwargs (Dict): A dictionary of arguments to pass to 404_backoff (bool): Whether to backoff on 404 when making a
request with a trailing slash (only affects request if
try_trailing_slash_on_400 is True).
send_request_args (Dict): A dictionary of arguments to pass to
`_send_request()`. `_send_request()`.
Returns: Returns:
Deferred[twisted.web.client.Response]: resolves with the HTTP Deferred[twisted.web.client.Response]: resolves with the HTTP
response object on success. response object on success.
""" """
response = yield self._send_request(**kwargs) response = yield self._send_request(**send_request_args)
if not try_trailing_slash_on_400: if not try_trailing_slash_on_400:
defer.returnValue(response) defer.returnValue(response)
...@@ -226,10 +231,10 @@ class MatrixFederationHttpClient(object): ...@@ -226,10 +231,10 @@ class MatrixFederationHttpClient(object):
# trailing slash on Synapse <=v0.99.2. # trailing slash on Synapse <=v0.99.2.
if (response.code == 400 and body.get("errcode") == "M_UNRECOGNIZED"): if (response.code == 400 and body.get("errcode") == "M_UNRECOGNIZED"):
# Enable backoff if initially disabled # Enable backoff if initially disabled
kwargs["backoff_on_404"] = backoff_on_404 send_request_args["backoff_on_404"] = backoff_on_404
kwargs["path"] += "/" send_request_args["path"] += "/"
response = yield self._send_request(**kwargs) response = yield self._send_request(**send_request_args)
defer.returnValue(response) defer.returnValue(response)
...@@ -581,7 +586,7 @@ class MatrixFederationHttpClient(object): ...@@ -581,7 +586,7 @@ class MatrixFederationHttpClient(object):
} }
response = yield self._send_request_with_optional_trailing_slash( response = yield self._send_request_with_optional_trailing_slash(
request, try_trailing_slash_on_400, **send_request_args) request, try_trailing_slash_on_400, backoff_on_404, send_request_args)
body = yield _handle_json_response( body = yield _handle_json_response(
self.hs.get_reactor(), self.default_timeout, request, response, self.hs.get_reactor(), self.default_timeout, request, response,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment