From 0f02b90cf12d75f40653acffde75563173bb1687 Mon Sep 17 00:00:00 2001 From: Mateusz Bocian Date: Thu, 1 May 2025 00:09:14 -0400 Subject: [PATCH] fix: address edge can read request body failures --- edge-runtime/lib/response.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/edge-runtime/lib/response.ts b/edge-runtime/lib/response.ts index 60cf9fd4b9..10e7070ae2 100644 --- a/edge-runtime/lib/response.ts +++ b/edge-runtime/lib/response.ts @@ -241,7 +241,11 @@ export const buildResponse = async ({ edgeResponse.headers.delete('x-middleware-next') // coookies set in middleware need to be available during the lambda request - const newRequest = new Request(request) + const newRequest = new Request(request.url, { + headers: request.headers, + method: request.method, + body: request.body && !request.bodyUsed ? await request.arrayBuffer() : undefined, + }) const newRequestCookies = mergeMiddlewareCookies(edgeResponse, newRequest) if (newRequestCookies) { newRequest.headers.set('Cookie', newRequestCookies)