File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import { getProxyForUrl } from "./proxy"
1313import { Storage } from "./storage"
1414import { expandPath } from "./util"
1515
16+ export const coderSessionTokenHeader = "Coder-Session-Token"
17+
1618/**
1719 * Return whether the API will need a token for authorization.
1820 * If mTLS is in use (as specified by the cert or key files being set) then
@@ -242,14 +244,15 @@ export async function waitForBuild(
242244 const baseUrl = new URL ( baseUrlRaw )
243245 const proto = baseUrl . protocol === "https:" ? "wss:" : "ws:"
244246 const socketUrlRaw = `${ proto } //${ baseUrl . host } ${ path } `
247+ const token = restClient . getAxiosInstance ( ) . defaults . headers . common [ coderSessionTokenHeader ] as string | undefined
245248 const socket = new ws . WebSocket ( new URL ( socketUrlRaw ) , {
246- headers : {
247- "Coder-Session-Token" : restClient . getAxiosInstance ( ) . defaults . headers . common [ "Coder-Session-Token" ] as
248- | string
249- | undefined ,
250- } ,
251- followRedirects : true ,
252249 agent : agent ,
250+ followRedirects : true ,
251+ headers : token
252+ ? {
253+ [ coderSessionTokenHeader ] : token ,
254+ }
255+ : undefined ,
253256 } )
254257 socket . binaryType = "nodebuffer"
255258 socket . on ( "message" , ( data ) => {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Workspace, GetInboxNotificationResponse } from "coder/site/src/api/type
33import { ProxyAgent } from "proxy-agent"
44import * as vscode from "vscode"
55import { WebSocket } from "ws"
6+ import { coderSessionTokenHeader } from "./api"
67import { errToStr } from "./api-helper"
78import { type Storage } from "./storage"
89
@@ -37,15 +38,15 @@ export class Inbox implements vscode.Disposable {
3738 const socketProto = baseUrl . protocol === "https:" ? "wss:" : "ws:"
3839 const socketUrl = `${ socketProto } //${ baseUrl . host } /api/v2/notifications/inbox/watch?format=plaintext&templates=${ watchTemplatesParam } &targets=${ watchTargetsParam } `
3940
40- const coderSessionTokenHeader = "Coder-Session-Token"
41+ const token = restClient . getAxiosInstance ( ) . defaults . headers . common [ coderSessionTokenHeader ] as string | undefined
4142 this . #socket = new WebSocket ( new URL ( socketUrl ) , {
42- followRedirects : true ,
4343 agent : httpAgent ,
44- headers : {
45- [ coderSessionTokenHeader ] : restClient . getAxiosInstance ( ) . defaults . headers . common [ coderSessionTokenHeader ] as
46- | string
47- | undefined ,
48- } ,
44+ followRedirects : true ,
45+ headers : token
46+ ? {
47+ [ coderSessionTokenHeader ] : token ,
48+ }
49+ : undefined ,
4950 } )
5051
5152 this . #socket. on ( "open" , ( ) => {
You can’t perform that action at this time.
0 commit comments