Skip to content

Commit

Permalink
Do not send body with HEAD and GET on node integration (#4105)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
dimitrov-adrian and natemoo-re authored Aug 2, 2022
1 parent 7088e86 commit 9cc3a11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-suits-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Do not send `body` with `HEAD` or `GET` requests when using `server` output.
5 changes: 3 additions & 2 deletions packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9cc3a11

Please sign in to comment.