Skip to content

Commit a03cf05

Browse files
authored
Only use the first 3 viaServers specified (#5034)
* Only use the first 3 viaServers specified To avoid HTTP 414 URI Too Long error Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent b3d2177 commit a03cf05

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/@types/requests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface IJoinRoomOpts {
3434

3535
/**
3636
* The server names to try and join through in addition to those that are automatically chosen.
37+
* Only the first 3 are actually used in the request, to avoid HTTP 414 Request-URI Too Long responses.
3738
*/
3839
viaServers?: string[];
3940

@@ -71,6 +72,7 @@ export interface KnockRoomOpts {
7172

7273
/**
7374
* The server names to try and knock through in addition to those that are automatically chosen.
75+
* Only the first 3 are actually used in the request, to avoid HTTP 414 Request-URI Too Long responses.
7476
*/
7577
viaServers?: string | string[];
7678
}

src/client.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,8 +2391,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
23912391
const queryParams: QueryDict = {};
23922392
if (opts.viaServers) {
23932393
// server_name has been deprecated in favour of via with Matrix >1.11 (MSC4156)
2394-
queryParams.server_name = opts.viaServers;
2395-
queryParams.via = opts.viaServers;
2394+
// We only use the first 3 servers, to avoid URI length issues.
2395+
queryParams.via = queryParams.server_name = opts.viaServers.slice(0, 3);
23962396
}
23972397

23982398
const data: IJoinRequestBody = {};
@@ -2436,9 +2436,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
24362436

24372437
const queryParams: QueryDict = {};
24382438
if (opts.viaServers) {
2439+
// We only use the first 3 servers, to avoid URI length issues.
2440+
const viaServers = Array.isArray(opts.viaServers) ? opts.viaServers.slice(0, 3) : [opts.viaServers];
24392441
// server_name has been deprecated in favour of via with Matrix >1.11 (MSC4156)
2440-
queryParams.server_name = opts.viaServers;
2441-
queryParams.via = opts.viaServers;
2442+
queryParams.server_name = viaServers;
2443+
queryParams.via = viaServers;
24422444
}
24432445

24442446
const body: Record<string, string> = {};

0 commit comments

Comments
 (0)