From 9cc3a11c44eaf042bb3a982c812e1d8e839faf8f Mon Sep 17 00:00:00 2001 From: Adrian Dimitrov Date: Tue, 2 Aug 2022 19:19:43 +0300 Subject: [PATCH] Do not send body with HEAD and GET on node integration (#4105) * Do not send body with HEAD and GET on node integration * Create seven-suits-sit.md Co-authored-by: Nate Moore --- .changeset/seven-suits-sit.md | 5 +++++ packages/astro/src/core/app/node.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/seven-suits-sit.md diff --git a/.changeset/seven-suits-sit.md b/.changeset/seven-suits-sit.md new file mode 100644 index 000000000..ca5570843 --- /dev/null +++ b/.changeset/seven-suits-sit.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Do not send `body` with `HEAD` or `GET` requests when using `server` output. diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index c7e6f1eca..17d800b1d 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -11,10 +11,11 @@ function createRequestFromNodeRequest(req: IncomingMessage, body?: Uint8Array): let url = `http://${req.headers.host}${req.url}`; let rawHeaders = req.headers as Record; const entries = Object.entries(rawHeaders); + const method = req.method || 'GET'; let request = new Request(url, { - method: req.method || 'GET', + method, headers: new Headers(entries), - body, + body: ['HEAD', 'GET'].includes(method) ? null : body, }); if (req.socket?.remoteAddress) { Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress);