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:
parent
444c2cda4f
commit
952c8f21e7
1 changed files with 6 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue