diff --git a/ext/node/polyfills/_http_outgoing.ts b/ext/node/polyfills/_http_outgoing.ts index 35526a3031..a6edc1144f 100644 --- a/ext/node/polyfills/_http_outgoing.ts +++ b/ext/node/polyfills/_http_outgoing.ts @@ -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(() => { diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 9a37722c78..b9fe767e6f 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -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(); + 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"); +});