Skip to content

Commit 3580cf7

Browse files
committed
fix: wrap websocket in proxy
1 parent edcb6f1 commit 3580cf7

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/node/routes/vscode.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { logError } from "../../common/util"
55
import { toVsCodeArgs } from "../cli"
66
import { isDevMode } from "../constants"
77
import { authenticated, ensureAuthenticated, redirect, self } from "../http"
8+
import { SocketProxyProvider } from "../socket"
89
import { loadAMDModule } from "../util"
910
import { Router as WsRouter } from "../wsRouter"
1011
import { errorHandler } from "./errors"
@@ -13,6 +14,7 @@ export class CodeServerRouteWrapper {
1314
/** Assigned in `ensureCodeServerLoaded` */
1415
private _codeServerMain!: CodeServerLib.IServerAPI
1516
private _wsRouterWrapper = WsRouter()
17+
private _socketProxyProvider = new SocketProxyProvider()
1618
public router = express.Router()
1719

1820
public get wsRouter() {
@@ -77,9 +79,10 @@ export class CodeServerRouteWrapper {
7779
}
7880

7981
private $proxyWebsocket = async (req: WebsocketRequest) => {
80-
this._codeServerMain.handleUpgrade(req, req.socket)
82+
const wrappedSocket = await this._socketProxyProvider.createProxy(req.ws)
83+
this._codeServerMain.handleUpgrade(req, wrappedSocket)
8184

82-
req.socket.resume()
85+
req.ws.resume()
8386
}
8487

8588
//#endregion
@@ -130,5 +133,6 @@ export class CodeServerRouteWrapper {
130133

131134
dispose() {
132135
this._codeServerMain?.dispose()
136+
this._socketProxyProvider.stop()
133137
}
134138
}

test/e2e/baseFixture.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { CodeServer, CodeServerPage } from "./models/CodeServer"
99
*
1010
* If `includeCredentials` is `true` page requests will be authenticated.
1111
*/
12-
export const describe = (name: string, includeCredentials: boolean, codeServerArgs: string[], fn: (codeServer: CodeServer) => void) => {
12+
export const describe = (
13+
name: string,
14+
includeCredentials: boolean,
15+
codeServerArgs: string[],
16+
fn: (codeServer: CodeServer) => void,
17+
) => {
1318
test.describe(name, () => {
1419
// This will spawn on demand so nothing is necessary on before.
1520
const codeServer = new CodeServer(name, codeServerArgs)
@@ -37,7 +42,7 @@ export const describe = (name: string, includeCredentials: boolean, codeServerAr
3742
// This provides a cookie that authenticates with code-server.
3843
storageState: includeCredentials ? storageState : {},
3944
// TODO@jsjoeio add note why we do this for testing cert stuff
40-
ignoreHTTPSErrors: true
45+
ignoreHTTPSErrors: true,
4146
})
4247

4348
fn(codeServer)

test/e2e/extensions.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function runTestExtensionTests() {
77

88
await codeServerPage.executeCommandViaMenus("code-server: Get proxy URI")
99

10-
// Click span:has-text("https://localhost:57989/proxy/{{port}}")
10+
// Click span:has-text("https://localhost:57989/proxy/{{port}}")
1111
await codeServerPage.page.waitForSelector(`span:has-text("${address}/proxy/{{port}}")`)
1212
})
1313
}
@@ -18,4 +18,4 @@ describe("Extensions", true, [], () => {
1818

1919
describe("Extensions with --cert", true, ["--cert"], () => {
2020
runTestExtensionTests()
21-
})
21+
})

0 commit comments

Comments
 (0)