Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d97271

Browse files
authored
Avoid using undefined token header (#466)
1 parentd696922 commit0d97271

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

‎src/api.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { getProxyForUrl } from "./proxy"
1313
import{Storage}from"./storage"
1414
import{expandPath}from"./util"
1515

16+
exportconstcoderSessionTokenHeader="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
constbaseUrl=newURL(baseUrlRaw)
243245
constproto=baseUrl.protocol==="https:" ?"wss:" :"ws:"
244246
constsocketUrlRaw=`${proto}//${baseUrl.host}${path}`
247+
consttoken=restClient.getAxiosInstance().defaults.headers.common[coderSessionTokenHeader]asstring|undefined
245248
constsocket=newws.WebSocket(newURL(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)=>{

‎src/inbox.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Workspace, GetInboxNotificationResponse } from "coder/site/src/api/type
33
import{ProxyAgent}from"proxy-agent"
44
import*asvscodefrom"vscode"
55
import{WebSocket}from"ws"
6+
import{coderSessionTokenHeader}from"./api"
67
import{errToStr}from"./api-helper"
78
import{typeStorage}from"./storage"
89

@@ -37,15 +38,15 @@ export class Inbox implements vscode.Disposable {
3738
constsocketProto=baseUrl.protocol==="https:" ?"wss:" :"ws:"
3839
constsocketUrl=`${socketProto}//${baseUrl.host}/api/v2/notifications/inbox/watch?format=plaintext&templates=${watchTemplatesParam}&targets=${watchTargetsParam}`
3940

40-
constcoderSessionTokenHeader="Coder-Session-Token"
41+
consttoken=restClient.getAxiosInstance().defaults.headers.common[coderSessionTokenHeader]asstring|undefined
4142
this.#socket=newWebSocket(newURL(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",()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp