Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http2 is failing with #421

Open
punkpeye opened this issue Sep 13, 2024 · 2 comments
Open

http2 is failing with #421

punkpeye opened this issue Sep 13, 2024 · 2 comments

Comments

@punkpeye
Copy link

capturing exception: could not handle request (058f571aa3784fe995c9e28941c65312) TypeError: Headers.append: ":method" is an invalid header name.
    at webidl.errors.exception (/Users/punkpeye/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/undici/lib/web/fetch/webidl.js:13:10)
    at webidl.errors.invalidArgument (/Users/punkpeye/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/undici/lib/web/fetch/webidl.js:29:24)
    at appendHeader (/Users/punkpeye/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/undici/lib/web/fetch/headers.js:89:25)
    at Headers.append (/Users/punkpeye/Developer/punkpeye/glama/node_modules/.pnpm/[email protected]/node_modules/undici/lib/web/fetch/headers.js:390:12)

If I enable http2 in fastify, then the requests fail with the above error.

@punkpeye
Copy link
Author

Not sure if this is the solution, but refactoring createRemixHeaders helped.

(
  fastifyHeaders: FastifyRequest['headers'],
): Headers => {
  const headers = new Headers();

  for (const [key, value] of Object.entries(fastifyHeaders)) {
    if (key.startsWith(':')) {
      if (key === ':authority' && typeof value === 'string') {
        headers.set('host', value);
      }

      continue;
    }

    if (Array.isArray(value)) {
      for (const member of value) headers.append(key, member);
    } else if (value) {
      headers.append(key, value);
    }
  }

  return headers;
};

@mcansh
Copy link
Owner

mcansh commented Sep 13, 2024

wait jk, i got it by removing installGlobals

old

what does your server look like? im not able to reproduce using the following

import fs from "node:fs";
import process from "node:process";
import chalk from "chalk";
import { remixFastify } from "@mcansh/remix-fastify";
import { installGlobals } from "@remix-run/node";
import { fastify } from "fastify";
import sourceMapSupport from "source-map-support";
import getPort, { portNumbers } from "get-port";

installGlobals();
sourceMapSupport.install();

const app = fastify({
  http2: true,
  https: {
    key: fs.readFileSync("server-key.pem"),
    cert: fs.readFileSync("server-cert.pem"),
  },
});

await app.register(remixFastify);

const host = process.env.HOST === "true" ? "0.0.0.0" : "127.0.0.1";
const desiredPort = Number(process.env.PORT) || 3000;
const portToUse = await getPort({
  port: portNumbers(desiredPort, desiredPort + 100),
});

let address = await app.listen({ port: portToUse, host });

if (portToUse !== desiredPort) {
  console.warn(
    chalk.yellow(
      `⚠️  Port ${desiredPort} is not available, using ${portToUse} instead.`,
    ),
  );
}

console.log(chalk.green(`✅ app ready: ${address}`));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants