From 5007cc94c4d4b3d22a9e2ffa049b687cf9f25e21 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 7 Oct 2024 14:55:25 +0100 Subject: [PATCH] fix: don't set statusMessage in HTTP/2 --- .changeset/strong-pugs-stare.md | 7 +++++++ packages/astro/src/core/app/node.ts | 6 +++++- packages/astro/src/vite-plugin-astro-server/response.ts | 6 +++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/strong-pugs-stare.md diff --git a/.changeset/strong-pugs-stare.md b/.changeset/strong-pugs-stare.md new file mode 100644 index 000000000000..2233b8e00b19 --- /dev/null +++ b/.changeset/strong-pugs-stare.md @@ -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. diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 9fa1b645ff22..60d2ac70d640 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -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 { diff --git a/packages/astro/src/vite-plugin-astro-server/response.ts b/packages/astro/src/vite-plugin-astro-server/response.ts index bc316d7c21f2..0dd3e1ff8dc1 100644 --- a/packages/astro/src/vite-plugin-astro-server/response.ts +++ b/packages/astro/src/vite-plugin-astro-server/response.ts @@ -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) {