mirror of
https://github.com/denoland/deno.git
synced 2025-02-12 16:59:32 -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
9a859318d6
commit
1ec76fb22a
2 changed files with 23 additions and 1 deletions
|
@ -540,7 +540,7 @@ export class OutgoingMessage extends Stream {
|
||||||
data = Buffer.from(data, encoding);
|
data = Buffer.from(data, encoding);
|
||||||
}
|
}
|
||||||
if (data instanceof Buffer) {
|
if (data instanceof Buffer) {
|
||||||
data = new Uint8Array(data.buffer);
|
data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
||||||
}
|
}
|
||||||
if (data.buffer.byteLength > 0) {
|
if (data.buffer.byteLength > 0) {
|
||||||
this._bodyWriter.write(data).then(() => {
|
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"));
|
const server = http.createServer((_req, res) => res.end("it works"));
|
||||||
assertEquals(server.address(), null);
|
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…
Add table
Reference in a new issue