From 952c8f21e738afcb4df5592fe9ad4bf46f052816 Mon Sep 17 00:00:00 2001 From: Mark Tiedemann Date: Thu, 12 Nov 2020 23:11:09 +0100 Subject: fix(std/http): flush body chunks for HTTP chunked encoding (#8349) Fixes #8339 --- std/http/_io.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'std/http') 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 { - 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 -- cgit v1.2.3