diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts index 91e2f57030edc5..3573416f83b5a7 100644 --- a/cli/tests/unit_node/http_test.ts +++ b/cli/tests/unit_node/http_test.ts @@ -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" + diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index fe589653447244..9356dde0ad5864 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -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 {