1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-27 17:49:08 -05:00

fix(std/http): flush body chunks for HTTP chunked encoding (#8349)

Fixes #8339
This commit is contained in:
Mark Tiedemann 2020-11-12 23:11:09 +01:00 committed by GitHub
parent 444c2cda4f
commit 952c8f21e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -171,21 +171,21 @@ function parseTrailer(field: string | null): Headers | undefined {
}
export async function writeChunkedBody(
w: Deno.Writer,
w: BufWriter,
r: Deno.Reader,
): Promise<void> {
const writer = BufWriter.create(w);
for await (const chunk of Deno.iter(r)) {
if (chunk.byteLength <= 0) continue;
const start = encoder.encode(`${chunk.byteLength.toString(16)}\r\n`);
const end = encoder.encode("\r\n");
await writer.write(start);
await writer.write(chunk);
await writer.write(end);
await w.write(start);
await w.write(chunk);
await w.write(end);
await w.flush();
}
const endChunk = encoder.encode("0\r\n\r\n");
await writer.write(endChunk);
await w.write(endChunk);
}
/** Write trailer headers to writer. It should mostly should be called after