summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-01-18 22:24:02 +0530
committerGitHub <noreply@github.com>2024-01-18 22:24:02 +0530
commit66ff28c21eac7f0cca0d3ccf141b1dc4cafa4888 (patch)
treed30535b5717276d5f276e974c0f1a7f366f24b12
parent2141543105dd9aabc0aca0534abc837f114e5bac (diff)
fix(node): update `req.socket` on WS upgrade (#21984)
Update the `req.socket` to be a `net.Socket` from `FakeSocket` Fixes #21979
-rw-r--r--cli/tests/unit_node/http_test.ts4
-rw-r--r--ext/node/polyfills/http.ts2
2 files changed, 5 insertions, 1 deletions
diff --git a/cli/tests/unit_node/http_test.ts b/cli/tests/unit_node/http_test.ts
index 91e2f5703..3573416f8 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 fe5896534..9356dde0a 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 {