Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ext/node): don't encode buffer data as utf8 in node:http2 #24016

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
satyarohith committed May 29, 2024
commit 3d7466ff73110bddf1867457c94d6d9c3e880068
25 changes: 20 additions & 5 deletions tests/unit_node/http2_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import * as http2 from "node:http2";
import { Buffer } from "node:buffer";
import fs from "node:fs";
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";
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";
Expand Down Expand Up @@ -173,13 +177,21 @@ Deno.test("[node/http2 client] write buffer on request stream works", async () =
const client = http2.connect(url)
client.on("error", (err) => console.error(err));

const imagePath = join(import.meta.dirname!, "testdata", "green.jpg");
console.log({ imagePath })
const buffer = await readFile(imagePath);
console.log({ bufferLength: buffer.length })
// const imageLength = buffer.length;
// console.log({ imageLength });
const req = client.request({ ":method": "POST", ":path": "/echo_server" });
req.write(Buffer.from("amazing"));
// req.write(new Uint8Array([1, 2, 3, 4]), (err) => console.error("write cb", err));
req.write(buffer, (err) => console.error("write cb", err));

let receivedData = "";
req.setEncoding("utf8");
let chunks: Buffer;
req.on("data", (chunk) => {
receivedData += chunk;
console.log("chunk receivedData", chunk);
// receivedData = Buffer.concat([receivedData, chunk]);
chunks = chunk;
});
req.end();

Expand All @@ -194,5 +206,8 @@ Deno.test("[node/http2 client] write buffer on request stream works", async () =
}, 2000);

await endPromise.promise;
assertEquals(receivedData, "amazing");
console.log("compare", buffer.compare(chunks!) === 0, buffer.length, chunks!.length)
// console.log("receivedData", receivedData);
// const expectedBuffer = fs.readFileSync("/Users/sr/c/denoland/deno/cat_dog.webp");
assertEquals(chunks!, buffer);
});
Binary file added tests/unit_node/testdata/green.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.