Archived
1
0

Support permessage-deflate web socket extension (#2846)

This commit is contained in:
Asher 2021-03-10 13:14:24 -06:00 committed by GitHub
parent f70a73bb89
commit 5a1f62a8fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -120,7 +120,7 @@ export class Vscode {
};
}
public async handleWebSocket(socket: net.Socket, query: Query, _permessageDeflate: boolean): Promise<true> {
public async handleWebSocket(socket: net.Socket, query: Query, permessageDeflate: boolean): Promise<true> {
if (!query.reconnectionToken) {
throw new Error('Reconnection token is missing from query parameters');
}
@ -128,7 +128,8 @@ export class Vscode {
reconnectionToken: <string>query.reconnectionToken,
reconnection: query.reconnection === 'true',
skipWebSocketFrames: query.skipWebSocketFrames === 'true',
// TODO: permessageDeflate,
permessageDeflate,
recordInflateBytes: permessageDeflate,
});
try {
await this.connect(await protocol.handshake(), protocol);

View File

@ -199,16 +199,20 @@ wsRouter.ws("/", ensureAuthenticated, async (req) => {
.createHash("sha1")
.update(req.headers["sec-websocket-key"] + magic)
.digest("base64")
req.ws.write(
[
const responseHeaders = [
"HTTP/1.1 101 Switching Protocols",
"Upgrade: websocket",
"Connection: Upgrade",
`Sec-WebSocket-Accept: ${reply}`,
].join("\r\n") + "\r\n\r\n",
)
// TODO: Parse this header properly. Currently unused so haven't bothered.
]
// TODO: Parse this header properly.
const extensions = req.headers["sec-websocket-extensions"]
const permessageDeflate = extensions ? extensions.includes("permessage-deflate") : false
responseHeaders.push("Sec-WebSocket-Extensions: permessage-deflate; server_max_window_bits=15")
req.ws.write(responseHeaders.join("\r\n") + "\r\n\r\n")
await vscode.sendWebsocket(req.ws, req.query, permessageDeflate)
})