0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

fix: don't set statusMessage in HTTP/2 (#12147)

This commit is contained in:
Matt Kane 2024-10-07 15:27:10 +01:00 committed by GitHub
parent 46cbf10c4b
commit 9db755ab7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 2 deletions

View file

@ -0,0 +1,7 @@
---
'astro': patch
---
Skips setting statusMessage header for HTTP/2 response
HTTP/2 doesn't support status message, so setting this was logging a warning.

View file

@ -6,6 +6,7 @@ import { createOutgoingHttpHeaders } from './createOutgoingHttpHeaders.js';
import { App } from './index.js';
import type { RenderOptions } from './index.js';
import type { SSRManifest, SerializedSSRManifest } from './types.js';
import { Http2ServerResponse } from 'node:http2';
export { apply as applyPolyfills } from '../polyfill.js';
@ -108,7 +109,10 @@ export class NodeApp extends App {
*/
static async writeResponse(source: Response, destination: ServerResponse) {
const { status, headers, body, statusText } = source;
destination.statusMessage = statusText;
// HTTP/2 doesn't support statusMessage
if (!(destination instanceof Http2ServerResponse)) {
destination.statusMessage = statusText;
}
destination.writeHead(status, createOutgoingHttpHeaders(headers));
if (!body) return destination.end();
try {

View file

@ -1,4 +1,5 @@
import type http from 'node:http';
import { Http2ServerResponse } from 'node:http2';
import type { ErrorWithMetadata } from '../core/errors/index.js';
import type { ModuleLoader } from '../core/module-loader/index.js';
@ -67,7 +68,10 @@ export async function writeWebResponse(res: http.ServerResponse, webResponse: Re
if (headers.has('set-cookie')) {
_headers['set-cookie'] = headers.getSetCookie();
}
res.statusMessage = statusText;
// HTTP/2 doesn't support statusMessage
if(!(res instanceof Http2ServerResponse)) {
res.statusMessage = statusText;
}
res.writeHead(status, _headers);
if (body) {
if (Symbol.for('astro.responseBody') in webResponse) {