Skip to content

Commit

Permalink
pass instance selector headers as query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Jan 29, 2025
1 parent d6ed1c4 commit 6b25230
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/app/Shared/Services/NotificationChannel.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,36 @@ export class NotificationChannel {
map((u) => {
try {
const wsUrl = new URL(u);
// set the proper protocol for WebSocket connection upgrade
wsUrl.protocol = wsUrl.protocol.replace('http', 'ws');

// set the instance namespace and name headers as query parameters instead.
// This is not used by normal Cryostat Web operation, where the instance is
// always the server that is hosting the web instance itself. In the console
// plugin case, the <namespace, name> instance selector is normally sent to
// the plugin backend by custom HTTP request headers so that the plugin backend
// can proxy to the correct Cryostat server instance. We cannot set custom
// request headers in the WebSocket connection request, so we set them as query
// parameters instead so that the plugin backend can fall back to finding those.
const headers = this.ctx.headers();
if (headers.has('CRYOSTAT-SVC-NS')) {
wsUrl.searchParams.append('ns', headers.get('CRYOSTAT-SVC-NS')!);
}
if (headers.has('CRYOSTAT-SVC-NAME')) {
wsUrl.searchParams.append('name', headers.get('CRYOSTAT-SVC-NAME')!);
}
return wsUrl.toString();
} catch (e) {
// wasn't a URL - assume it was a relative path alone, which is OK
return u;
const headers = this.ctx.headers();
const searchParams = new URLSearchParams();
if (headers.has('CRYOSTAT-SVC-NS')) {
searchParams.append('ns', headers.get('CRYOSTAT-SVC-NS')!);
}
if (headers.has('CRYOSTAT-SVC-NAME')) {
searchParams.append('name', headers.get('CRYOSTAT-SVC-NAME')!);
}
return `${u}?${searchParams}`;
}
}),
),
Expand Down

0 comments on commit 6b25230

Please sign in to comment.