From 6902b884feb12b5c3be8cf3c6c8b15fa47cd51c1 Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Thu, 28 Dec 2023 11:46:54 +0000 Subject: [PATCH] fix(astro): Handle non-utf8 encoded streams in middleware --- packages/astro/src/server/middleware.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/astro/src/server/middleware.ts b/packages/astro/src/server/middleware.ts index 7b4a02cceddf..907714d33874 100644 --- a/packages/astro/src/server/middleware.ts +++ b/packages/astro/src/server/middleware.ts @@ -162,7 +162,7 @@ async function instrumentRequest( const newResponseStream = new ReadableStream({ start: async controller => { for await (const chunk of originalBody) { - const html = typeof chunk === 'string' ? chunk : decoder.decode(chunk); + const html = typeof chunk === 'string' ? chunk : decoder.decode(chunk, { stream: true }); const modifiedHtml = addMetaTagToHead(html, scope, client, span); controller.enqueue(new TextEncoder().encode(modifiedHtml)); }