From f612ee21baa50c1f4ca0e46d2b2997489c091e08 Mon Sep 17 00:00:00 2001 From: aricart Date: Sun, 3 Dec 2023 14:38:37 -0400 Subject: [PATCH] [FIX] on websocket rewriting of the urls requires additional information, added a hint to the url parse which designates whether gossiped URLs should be ws or wss based on current transport rather than on other heuristics. --- nats-base-client/core.ts | 2 +- nats-base-client/protocol.ts | 2 +- nats-base-client/servers.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nats-base-client/core.ts b/nats-base-client/core.ts index d4b7d666..7abdfe3d 100644 --- a/nats-base-client/core.ts +++ b/nats-base-client/core.ts @@ -1422,7 +1422,7 @@ export interface Base { } export interface URLParseFn { - (u: string): string; + (u: string, encrypted?: boolean): string; } export enum ServiceVerb { diff --git a/nats-base-client/protocol.ts b/nats-base-client/protocol.ts index a713593b..e0e49ea9 100644 --- a/nats-base-client/protocol.ts +++ b/nats-base-client/protocol.ts @@ -802,7 +802,7 @@ export class ProtocolHandler implements Dispatcher { this.info = info; const updates = this.options && this.options.ignoreClusterUpdates ? undefined - : this.servers.update(info); + : this.servers.update(info, this.transport.isEncrypted()); if (!this.infoReceived) { this.features.update(parseSemVer(info.version)); this.infoReceived = true; diff --git a/nats-base-client/servers.ts b/nats-base-client/servers.ts index fcf41dbf..e7c28205 100644 --- a/nats-base-client/servers.ts +++ b/nats-base-client/servers.ts @@ -282,7 +282,7 @@ export class Servers { return this.servers; } - update(info: ServerInfo): ServersChanged { + update(info: ServerInfo, encrypted?: boolean): ServersChanged { const added: string[] = []; let deleted: string[] = []; @@ -290,7 +290,7 @@ export class Servers { const discovered = new Map(); if (info.connect_urls && info.connect_urls.length > 0) { info.connect_urls.forEach((hp) => { - hp = urlParseFn ? urlParseFn(hp) : hp; + hp = urlParseFn ? urlParseFn(hp, encrypted) : hp; const s = new ServerImpl(hp, true); discovered.set(hp, s); });