Skip to content

Commit

Permalink
fix: don't set statusMessage in HTTP/2 (#12147)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic authored Oct 7, 2024
1 parent 46cbf10 commit 9db755a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/strong-pugs-stare.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 5 additions & 1 deletion packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/response.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9db755a

Please sign in to comment.