|
61 | 61 | event_from_pdu_json, |
62 | 62 | ) |
63 | 63 | from synapse.federation.transport.client import SendJoinResponse |
| 64 | +from synapse.http.client import is_unknown_endpoint |
64 | 65 | from synapse.http.types import QueryParams |
65 | 66 | from synapse.logging.opentracing import SynapseTags, log_kv, set_tag, tag_args, trace |
66 | 67 | from synapse.types import JsonDict, UserID, get_domain_from_id |
@@ -759,43 +760,6 @@ async def get_event_auth( |
759 | 760 |
|
760 | 761 | return signed_auth |
761 | 762 |
|
762 | | - def _is_unknown_endpoint( |
763 | | - self, e: HttpResponseException, synapse_error: Optional[SynapseError] = None |
764 | | - ) -> bool: |
765 | | - """ |
766 | | - Returns true if the response was due to an endpoint being unimplemented. |
767 | | -
|
768 | | - Args: |
769 | | - e: The error response received from the remote server. |
770 | | - synapse_error: The above error converted to a SynapseError. This is |
771 | | - automatically generated if not provided. |
772 | | -
|
773 | | - """ |
774 | | - if synapse_error is None: |
775 | | - synapse_error = e.to_synapse_error() |
776 | | - # MSC3743 specifies that servers should return a 404 or 405 with an errcode |
777 | | - # of M_UNRECOGNIZED when they receive a request to an unknown endpoint or |
778 | | - # to an unknown method, respectively. |
779 | | - # |
780 | | - # Older versions of servers don't properly handle this. This needs to be |
781 | | - # rather specific as some endpoints truly do return 404 errors. |
782 | | - return ( |
783 | | - # 404 is an unknown endpoint, 405 is a known endpoint, but unknown method. |
784 | | - (e.code == 404 or e.code == 405) |
785 | | - and ( |
786 | | - # Older Dendrites returned a text or empty body. |
787 | | - # Older Conduit returned an empty body. |
788 | | - not e.response |
789 | | - or e.response == b"404 page not found" |
790 | | - # The proper response JSON with M_UNRECOGNIZED errcode. |
791 | | - or synapse_error.errcode == Codes.UNRECOGNIZED |
792 | | - ) |
793 | | - ) or ( |
794 | | - # Older Synapses returned a 400 error. |
795 | | - e.code == 400 |
796 | | - and synapse_error.errcode == Codes.UNRECOGNIZED |
797 | | - ) |
798 | | - |
799 | 763 | async def _try_destination_list( |
800 | 764 | self, |
801 | 765 | description: str, |
@@ -887,7 +851,7 @@ async def _try_destination_list( |
887 | 851 | elif 400 <= e.code < 500 and synapse_error.errcode in failover_errcodes: |
888 | 852 | failover = True |
889 | 853 |
|
890 | | - elif failover_on_unknown_endpoint and self._is_unknown_endpoint( |
| 854 | + elif failover_on_unknown_endpoint and is_unknown_endpoint( |
891 | 855 | e, synapse_error |
892 | 856 | ): |
893 | 857 | failover = True |
@@ -1223,7 +1187,7 @@ async def _do_send_join( |
1223 | 1187 | # If an error is received that is due to an unrecognised endpoint, |
1224 | 1188 | # fallback to the v1 endpoint. Otherwise, consider it a legitimate error |
1225 | 1189 | # and raise. |
1226 | | - if not self._is_unknown_endpoint(e): |
| 1190 | + if not is_unknown_endpoint(e): |
1227 | 1191 | raise |
1228 | 1192 |
|
1229 | 1193 | logger.debug("Couldn't send_join with the v2 API, falling back to the v1 API") |
@@ -1297,7 +1261,7 @@ async def _do_send_invite( |
1297 | 1261 | # fallback to the v1 endpoint if the room uses old-style event IDs. |
1298 | 1262 | # Otherwise, consider it a legitimate error and raise. |
1299 | 1263 | err = e.to_synapse_error() |
1300 | | - if self._is_unknown_endpoint(e, err): |
| 1264 | + if is_unknown_endpoint(e, err): |
1301 | 1265 | if room_version.event_format != EventFormatVersions.ROOM_V1_V2: |
1302 | 1266 | raise SynapseError( |
1303 | 1267 | 400, |
@@ -1358,7 +1322,7 @@ async def _do_send_leave(self, destination: str, pdu: EventBase) -> JsonDict: |
1358 | 1322 | # If an error is received that is due to an unrecognised endpoint, |
1359 | 1323 | # fallback to the v1 endpoint. Otherwise, consider it a legitimate error |
1360 | 1324 | # and raise. |
1361 | | - if not self._is_unknown_endpoint(e): |
| 1325 | + if not is_unknown_endpoint(e): |
1362 | 1326 | raise |
1363 | 1327 |
|
1364 | 1328 | logger.debug("Couldn't send_leave with the v2 API, falling back to the v1 API") |
@@ -1629,7 +1593,7 @@ async def send_request( |
1629 | 1593 | # If an error is received that is due to an unrecognised endpoint, |
1630 | 1594 | # fallback to the unstable endpoint. Otherwise, consider it a |
1631 | 1595 | # legitimate error and raise. |
1632 | | - if not self._is_unknown_endpoint(e): |
| 1596 | + if not is_unknown_endpoint(e): |
1633 | 1597 | raise |
1634 | 1598 |
|
1635 | 1599 | logger.debug( |
|
0 commit comments