summaryrefslogtreecommitdiff
path: root/tests/unit_node/http2_test.ts
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2024-05-29 11:34:34 +0530
committerGitHub <noreply@github.com>2024-05-29 11:34:34 +0530
commit4f9b23b3664578c2bf48415db246fb21e49abddb (patch)
tree2f4d63bd4fdcc9d82dda7c4588dbad119f03a9d3 /tests/unit_node/http2_test.ts
parenta8923534ed02e9e4ba3bb277db6e61a208c64125 (diff)
fix(ext/node): don't encode buffer data as utf8 in http2 (#24016)
Diffstat (limited to 'tests/unit_node/http2_test.ts')
-rw-r--r--tests/unit_node/http2_test.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts
index 872e6641e..f2604b344 100644
--- a/tests/unit_node/http2_test.ts
+++ b/tests/unit_node/http2_test.ts
@@ -1,6 +1,9 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import * as http2 from "node:http2";
+import { Buffer } from "node:buffer";
+import { readFile } from "node:fs/promises";
+import { join } from "node:path";
import * as net from "node:net";
import { assert, assertEquals } from "@std/assert/mod.ts";
import { curlRequest } from "../unit/test_util.ts";
@@ -164,3 +167,39 @@ Deno.test("[node/http2.createServer()]", {
// Issue: https://github.com/denoland/deno/issues/22764
await new Promise<void>((resolve) => server.on("close", resolve));
});
+
+Deno.test("[node/http2 client] write image buffer on request stream works", async () => {
+ const url = "https://localhost:5545";
+ const client = http2.connect(url);
+ client.on("error", (err) => console.error(err));
+
+ const imagePath = join(import.meta.dirname!, "testdata", "green.jpg");
+ const buffer = await readFile(imagePath);
+ const req = client.request({ ":method": "POST", ":path": "/echo_server" });
+ req.write(buffer, (err) => {
+ if (err) throw err;
+ });
+
+ let receivedData: Buffer;
+ req.on("data", (chunk) => {
+ if (!receivedData) {
+ receivedData = chunk;
+ } else {
+ receivedData = Buffer.concat([receivedData, chunk]);
+ }
+ });
+ req.end();
+
+ const endPromise = Promise.withResolvers<void>();
+ setTimeout(() => {
+ try {
+ client.close();
+ } catch (_) {
+ // pass
+ }
+ endPromise.resolve();
+ }, 2000);
+
+ await endPromise.promise;
+ assertEquals(receivedData!, buffer);
+});