diff options
author | Mark Tiedemann <www.marktiedemann@gmail.com> | 2020-11-12 23:11:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-13 09:11:09 +1100 |
commit | 952c8f21e738afcb4df5592fe9ad4bf46f052816 (patch) | |
tree | 68effae6b32577ce9aee8108fe361e2dbd269060 | |
parent | 444c2cda4fe4b48ef11fb13848bbedae2d04118e (diff) |
fix(std/http): flush body chunks for HTTP chunked encoding (#8349)
Fixes #8339
-rw-r--r-- | std/http/_io.ts | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/std/http/_io.ts b/std/http/_io.ts index 1375edbb5..1b6383acc 100644 --- a/std/http/_io.ts +++ b/std/http/_io.ts @@ -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 |