1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/node): http request uploads of subarray of buffer should work (#24603)

Closes https://github.com/denoland/deno/issues/24571
This commit is contained in:
Satya Rohith 2024-07-16 17:46:40 +05:30 committed by GitHub
parent 04f9db5b22
commit 6421dc33ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -540,7 +540,7 @@ export class OutgoingMessage extends Stream {
data = Buffer.from(data, encoding);
}
if (data instanceof Buffer) {
data = new Uint8Array(data.buffer);
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (data.buffer.byteLength > 0) {
this._bodyWriter.write(data).then(() => {

View file

@ -1406,3 +1406,25 @@ Deno.test("[node/http] Server.address() can be null", () => {
const server = http.createServer((_req, res) => res.end("it works"));
assertEquals(server.address(), null);
});
Deno.test("[node/http] ClientRequest PUT subarray", async () => {
const buffer = Buffer.from("hello world");
const payload = buffer.subarray(6, 11);
let body = "";
const { promise, resolve, reject } = Promise.withResolvers<void>();
const req = http.request("http://localhost:4545/echo_server", {
method: "PUT",
}, (resp) => {
resp.on("data", (chunk) => {
body += chunk;
});
resp.on("end", () => {
resolve();
});
});
req.once("error", (e) => reject(e));
req.end(payload);
await promise;
assertEquals(body, "world");
});