fix(astro/core/app/node): support http2 requests (#7215)

This commit is contained in:
Benjamin MENANT 2023-06-02 10:51:09 +02:00 committed by GitHub
parent fea3069360
commit 6e27f2f6db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Node adapter fallbacks to `:authority` http2 pseudo-header when `host` is nullish.

View file

@ -14,11 +14,12 @@ function createRequestFromNodeRequest(req: NodeIncomingMessage, body?: Uint8Arra
req.socket instanceof TLSSocket || req.headers['x-forwarded-proto'] === 'https'
? 'https'
: 'http';
let url = `${protocol}://${req.headers.host}${req.url}`;
let rawHeaders = req.headers as Record<string, any>;
const hostname = req.headers.host || req.headers[':authority'];
const url = `${protocol}://${hostname}${req.url}`;
const rawHeaders = req.headers as Record<string, any>;
const entries = Object.entries(rawHeaders);
const method = req.method || 'GET';
let request = new Request(url, {
const request = new Request(url, {
method,
headers: new Headers(entries),
body: ['HEAD', 'GET'].includes(method) ? null : body,