Check native sliding sync support against an unstable feature flag (#12498)
* Check native sliding sync support against an unstable feature flag The `OPTIONS` approach from https://github.com/matrix-org/matrix-react-sdk/pull/12492 doesn't work because Synapse *always* responds with 204 (success) to `OPTIONS` requests, as described here: https://github.com/element-hq/synapse/issues/17153 We further can't use `HEAD` because it's not part of the allowed CORS methods, meaning the browser will mask the exact status code and error message from us, and the proxy hangs on the request anyways: https://github.com/matrix-org/sliding-sync/pull/429 To avoid these problems, we instead search for an unstable feature flag to be exposed by the server. Presence of this flag denotes native support. See https://github.com/matrix-org/matrix-spec-proposals/pull/3575/files#r1588877046 for details. Implementations which support sliding sync natively will need to update to support this new unstable feature flag usage. * Appease the linter * Appease the tests
This commit is contained in:
@@ -372,26 +372,18 @@ export class SlidingSyncManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the server "natively" supports sliding sync (at the unstable endpoint).
|
||||
* Check if the server "natively" supports sliding sync (with an unstable endpoint).
|
||||
* @param client The MatrixClient to use
|
||||
* @return Whether the "native" (unstable) endpoint is up
|
||||
* @return Whether the "native" (unstable) endpoint is supported
|
||||
*/
|
||||
public async nativeSlidingSyncSupport(client: MatrixClient): Promise<boolean> {
|
||||
try {
|
||||
// We use OPTIONS to avoid causing a real sync to happen, as that may be intensive or encourage
|
||||
// middleware software to start polling as our access token (thus stealing our to-device messages).
|
||||
// See https://github.com/element-hq/element-web/issues/27426
|
||||
// XXX: Using client.http is a bad thing - it's meant to be private access. See `client.http` for details.
|
||||
await client.http.authedRequest<void>(Method.Options, "/sync", undefined, undefined, {
|
||||
localTimeoutMs: 10 * 1000, // 10s
|
||||
prefix: "/_matrix/client/unstable/org.matrix.msc3575",
|
||||
});
|
||||
} catch (e) {
|
||||
return false; // 404, M_UNRECOGNIZED
|
||||
// Per https://github.com/matrix-org/matrix-spec-proposals/pull/3575/files#r1589542561
|
||||
// `client` can be undefined/null in tests for some reason.
|
||||
const support = await client?.doesServerSupportUnstableFeature("org.matrix.msc3575");
|
||||
if (support) {
|
||||
logger.log("nativeSlidingSyncSupport: sliding sync advertised as unstable");
|
||||
}
|
||||
|
||||
logger.log("nativeSlidingSyncSupport: sliding sync endpoint is up");
|
||||
return true; // 200, OK
|
||||
return support;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user