mirror of
https://github.com/denoland/deno.git
synced 2025-07-24 05:35:33 +00:00
fix(ext/http): truncate read bytes when streaming bodies (#14389)
stream shutdown wasn't happening correctly (moved it to call op_http_shutdown) & extra zeroed bytes were being sent for when body length not a multiple of 64*1024
This commit is contained in:
parent
c0e3b6096d
commit
609c359dd4
3 changed files with 35 additions and 20 deletions
|
@ -854,6 +854,32 @@ Deno.test({ permissions: { net: true } }, async function httpServerPanic() {
|
|||
listener.close();
|
||||
});
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { net: true, write: true, read: true } },
|
||||
async function httpServerCorrectSizeResponse() {
|
||||
const tmpFile = await Deno.makeTempFile();
|
||||
const file = await Deno.open(tmpFile, { write: true, read: true });
|
||||
await file.write(new Uint8Array(70 * 1024).fill(1)); // 70kb sent in 64kb + 6kb chunks
|
||||
file.close();
|
||||
const promise = (async () => {
|
||||
const listener = Deno.listen({ port: 4503 });
|
||||
const conn = await listener.accept();
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
const ev = await httpConn.nextRequest();
|
||||
const { respondWith } = ev!;
|
||||
const f = await Deno.open(tmpFile, { read: true });
|
||||
await respondWith(new Response(f.readable, { status: 200 }));
|
||||
httpConn.close();
|
||||
listener.close();
|
||||
f.close();
|
||||
})();
|
||||
const resp = await fetch("http://127.0.0.1:4503/");
|
||||
const body = await resp.arrayBuffer();
|
||||
assertEquals(body.byteLength, 70 * 1024);
|
||||
await promise;
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { net: true, write: true, read: true } },
|
||||
async function httpServerClosedStream() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue