diff options
author | Sean McArthur <sean@seanmonstar.com> | 2024-08-14 14:59:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-14 21:59:22 +0000 |
commit | 875ee618d318ea748e38641108d906eff34a9f86 (patch) | |
tree | 05662499b61e6638f97e4301cb80ef8292ae66d1 /tests/unit_node/http2_test.ts | |
parent | 4eff1e8ec4c12c709ce7e0e6d430ecbbc571bfbe (diff) |
feat(ext/node): support http2session.socket (#24786)
Co-authored-by: Satya Rohith <me@satyarohith.com>
Diffstat (limited to 'tests/unit_node/http2_test.ts')
-rw-r--r-- | tests/unit_node/http2_test.ts | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts index edaac8234..7cffd0432 100644 --- a/tests/unit_node/http2_test.ts +++ b/tests/unit_node/http2_test.ts @@ -275,3 +275,41 @@ Deno.test("[node/http2 client] deno doesn't panic on uppercase headers", async ( await endPromise.promise; assertEquals(receivedData, "hello world\n"); }); + +Deno.test("[node/http2 ClientHttp2Session.socket]", async () => { + const url = "http://127.0.0.1:4246"; + const client = http2.connect(url); + client.on("error", (err) => console.error(err)); + + const req = client.request({ ":method": "POST", ":path": "/" }); + const endPromise = Promise.withResolvers<void>(); + + // test that we can access session.socket + client.socket.setTimeout(10000); + // nodejs allows setting arbitrary properties + // deno-lint-ignore no-explicit-any + (client.socket as any).nonExistant = 9001; + // deno-lint-ignore no-explicit-any + assertEquals((client.socket as any).nonExistant, 9001); + + // regular request dance to make sure it keeps working + let receivedData = ""; + req.write("hello"); + req.setEncoding("utf8"); + + req.on("data", (chunk) => { + receivedData += chunk; + }); + req.on("end", () => { + req.close(); + client.close(); + endPromise.resolve(); + }); + req.end(); + await endPromise.promise; + assertEquals(client.socket.remoteAddress, "127.0.0.1"); + assertEquals(client.socket.remotePort, 4246); + assertEquals(client.socket.remoteFamily, "IPv4"); + client.socket.setTimeout(0); + assertEquals(receivedData, "hello world\n"); +}); |