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 <natemoo-re@users.noreply.github.com>
This commit is contained in:
Adrian Dimitrov 2022-08-02 19:19:43 +03:00 committed by GitHub
parent 7088e86c64
commit 9cc3a11c44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Do not send `body` with `HEAD` or `GET` requests when using `server` output.

View file

@ -11,10 +11,11 @@ function createRequestFromNodeRequest(req: IncomingMessage, body?: Uint8Array):
let url = `http://${req.headers.host}${req.url}`;
let rawHeaders = req.headers as Record<string, any>;
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);