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

Strip HTTP/2 pseudo headers from dev server requests #12830

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-sloths-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-router/dev": patch
---

Strip HTTP/2 pseudo headers from dev server requests - Fixes using HTTPS with the dev server
19 changes: 16 additions & 3 deletions packages/react-router-dev/vite/node-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncomingHttpHeaders, ServerResponse } from "node:http";
import type { IncomingMessage, ServerResponse } from "node:http";
import { once } from "node:events";
import { Readable } from "node:stream";
import { splitCookiesString } from "set-cookie-parser";
Expand All @@ -12,7 +12,20 @@ export type NodeRequestHandler = (
res: ServerResponse
) => Promise<void>;

function fromNodeHeaders(nodeHeaders: IncomingHttpHeaders): Headers {
function fromNodeHeaders(nodeReq: IncomingMessage): Headers {
let nodeHeaders = nodeReq.headers;

if (nodeReq.httpVersionMajor >= 2) {
nodeHeaders = { ...nodeHeaders };
if (nodeHeaders[":authority"]) {
nodeHeaders.host = nodeHeaders[":authority"] as string;
}
delete nodeHeaders[":authority"];
delete nodeHeaders[":method"];
delete nodeHeaders[":path"];
delete nodeHeaders[":scheme"];
}

let headers = new Headers();

for (let [key, values] of Object.entries(nodeHeaders)) {
Expand Down Expand Up @@ -50,7 +63,7 @@ export function fromNodeRequest(
let controller: AbortController | null = new AbortController();
let init: RequestInit = {
method: nodeReq.method,
headers: fromNodeHeaders(nodeReq.headers),
headers: fromNodeHeaders(nodeReq),
signal: controller.signal,
};

Expand Down
Loading