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:
parent
7088e86c64
commit
9cc3a11c44
2 changed files with 8 additions and 2 deletions
5
.changeset/seven-suits-sit.md
Normal file
5
.changeset/seven-suits-sit.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"astro": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Do not send `body` with `HEAD` or `GET` requests when using `server` output.
|
|
@ -11,10 +11,11 @@ function createRequestFromNodeRequest(req: IncomingMessage, body?: Uint8Array):
|
||||||
let url = `http://${req.headers.host}${req.url}`;
|
let url = `http://${req.headers.host}${req.url}`;
|
||||||
let rawHeaders = req.headers as Record<string, any>;
|
let rawHeaders = req.headers as Record<string, any>;
|
||||||
const entries = Object.entries(rawHeaders);
|
const entries = Object.entries(rawHeaders);
|
||||||
|
const method = req.method || 'GET';
|
||||||
let request = new Request(url, {
|
let request = new Request(url, {
|
||||||
method: req.method || 'GET',
|
method,
|
||||||
headers: new Headers(entries),
|
headers: new Headers(entries),
|
||||||
body,
|
body: ['HEAD', 'GET'].includes(method) ? null : body,
|
||||||
});
|
});
|
||||||
if (req.socket?.remoteAddress) {
|
if (req.socket?.remoteAddress) {
|
||||||
Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress);
|
Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress);
|
||||||
|
|
Loading…
Reference in a new issue