mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-08 02:52:15 -04:00
Remove trailing slashes from outbound federation requests and retry on 400 (#4840)
As per #3622, we remove trailing slashes from outbound federation requests. However, to ensure that we remain backwards compatible with previous versions of Synapse, if we receive a HTTP 400 with `M_UNRECOGNIZED`, then we are likely talking to an older version of Synapse in which case we retry with a trailing slash appended to the request path.
This commit is contained in:
commit
7bef97dfb7
5 changed files with 191 additions and 17 deletions
|
@ -51,9 +51,10 @@ class TransportLayerClient(object):
|
|||
logger.debug("get_room_state dest=%s, room=%s",
|
||||
destination, room_id)
|
||||
|
||||
path = _create_v1_path("/state/%s/", room_id)
|
||||
path = _create_v1_path("/state/%s", room_id)
|
||||
return self.client.get_json(
|
||||
destination, path=path, args={"event_id": event_id},
|
||||
try_trailing_slash_on_400=True,
|
||||
)
|
||||
|
||||
@log_function
|
||||
|
@ -73,9 +74,10 @@ class TransportLayerClient(object):
|
|||
logger.debug("get_room_state_ids dest=%s, room=%s",
|
||||
destination, room_id)
|
||||
|
||||
path = _create_v1_path("/state_ids/%s/", room_id)
|
||||
path = _create_v1_path("/state_ids/%s", room_id)
|
||||
return self.client.get_json(
|
||||
destination, path=path, args={"event_id": event_id},
|
||||
try_trailing_slash_on_400=True,
|
||||
)
|
||||
|
||||
@log_function
|
||||
|
@ -95,8 +97,11 @@ class TransportLayerClient(object):
|
|||
logger.debug("get_pdu dest=%s, event_id=%s",
|
||||
destination, event_id)
|
||||
|
||||
path = _create_v1_path("/event/%s/", event_id)
|
||||
return self.client.get_json(destination, path=path, timeout=timeout)
|
||||
path = _create_v1_path("/event/%s", event_id)
|
||||
return self.client.get_json(
|
||||
destination, path=path, timeout=timeout,
|
||||
try_trailing_slash_on_400=True,
|
||||
)
|
||||
|
||||
@log_function
|
||||
def backfill(self, destination, room_id, event_tuples, limit):
|
||||
|
@ -121,7 +126,7 @@ class TransportLayerClient(object):
|
|||
# TODO: raise?
|
||||
return
|
||||
|
||||
path = _create_v1_path("/backfill/%s/", room_id)
|
||||
path = _create_v1_path("/backfill/%s", room_id)
|
||||
|
||||
args = {
|
||||
"v": event_tuples,
|
||||
|
@ -132,6 +137,7 @@ class TransportLayerClient(object):
|
|||
destination,
|
||||
path=path,
|
||||
args=args,
|
||||
try_trailing_slash_on_400=True,
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
|
@ -176,6 +182,7 @@ class TransportLayerClient(object):
|
|||
json_data_callback=json_data_callback,
|
||||
long_retries=True,
|
||||
backoff_on_404=True, # If we get a 404 the other side has gone
|
||||
try_trailing_slash_on_400=True,
|
||||
)
|
||||
|
||||
defer.returnValue(response)
|
||||
|
@ -959,7 +966,7 @@ def _create_v1_path(path, *args):
|
|||
|
||||
Example:
|
||||
|
||||
_create_v1_path("/event/%s/", event_id)
|
||||
_create_v1_path("/event/%s", event_id)
|
||||
|
||||
Args:
|
||||
path (str): String template for the path
|
||||
|
@ -980,7 +987,7 @@ def _create_v2_path(path, *args):
|
|||
|
||||
Example:
|
||||
|
||||
_create_v2_path("/event/%s/", event_id)
|
||||
_create_v2_path("/event/%s", event_id)
|
||||
|
||||
Args:
|
||||
path (str): String template for the path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue