mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -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:
parent
04f9db5b22
commit
6421dc33ed
2 changed files with 23 additions and 1 deletions
|
@ -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(() => {
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue