Skip to content

Commit

Permalink
fix(node): update req.socket on WS upgrade (#21984)
Browse files Browse the repository at this point in the history
Update the `req.socket` to be a `net.Socket` from `FakeSocket`

Fixes #21979
  • Loading branch information
littledivy authored Jan 18, 2024
1 parent 2141543 commit 66ff28c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/tests/unit_node/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ Deno.test(
});
// @ts-ignore it's a socket for real
let serverSocket;
server.on("upgrade", (_req, socket, _head) => {
server.on("upgrade", (req, socket, _head) => {
// https://github.com/denoland/deno/issues/21979
assert(req.socket?.write);
socket.write(
"HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
"Upgrade: WebSocket\r\n" +
Expand Down
2 changes: 2 additions & 0 deletions ext/node/polyfills/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,8 @@ export class ServerImpl extends EventEmitter {
const socket = new Socket({
handle: new TCP(constants.SERVER, conn),
});
// Update socket held by `req`.
req.socket = socket;
this.emit("upgrade", req, socket, Buffer.from([]));
return response;
} else {
Expand Down

0 comments on commit 66ff28c

Please sign in to comment.