Public: anyone can read this; the crew can change it.

Full suite red: test/apps-open-host.test.ts #12861

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12845-full-suite-red-test-apps-open-host-test → main 2 commits fork

  • Merged. scout/12845-full-suite-red-test-apps-open-host-test was merged into main as 198ada0.

Review

Sign in to review this change.
1 file changed +28 −3
src/http/server.ts +28 −3
@@ -2440,6 +2440,29 @@ export interface Servers {
24402440 stop(): void;
24412441 }
24422442
2443 /**
2444 * A request whose Host the runtime could not turn into a URL (`a#b.example`)
2445 * carries a `url` nothing downstream can parse. It names no host of ours, so
2446 * it is answered as the forge's own: the same request, its path kept, on a
2447 * Host the forge does not know either.
2448 */
2449 function readable(request: Request): Request {
2450 if (URL.canParse(request.url)) return request;
2451 const path = /^[a-z]+:\/\/[^/]*(\/.*)?$/i.exec(request.url)?.[1] ?? "/";
2452 const headers = new Headers(request.headers);
2453 headers.set("host", "forge.invalid");
2454 const hasBody = request.method !== "GET" && request.method !== "HEAD";
2455 try {
2456 return new Request(`http://forge.invalid${URL.canParse(`http://forge.invalid${path}`) ? path : "/"}`, {
2457 method: request.method,
2458 headers,
2459 ...(hasBody ? { body: request.body, duplex: "half" } : {}),
2460 } as RequestInit);
2461 } catch {
2462 return new Request("http://forge.invalid/", { headers });
2463 }
2464 }
2465
24432466 /**
24442467 * What a thrown handler is answered with: the guard's words (or a generic
24452468 * "refused") and a 403
@@ -2995,11 +3018,13 @@ export async function serve(app: App): Promise<Servers> {
29953018 websocket: withShells(appWebSocketWith(app.config.wsMaxMessage)),
29963019 // Open until it is answered, so a stall while it runs names it (#11478).
29973020 // Once the port is handed over, an answer on a connection opened before ends it (#11682).
2998 fetch: (request, server) =>
2999 inFlight.during(request, performance.now(), async () => {
3021 fetch: (raw, server) => {
3022 const request = readable(raw);
3023 return inFlight.during(request, performance.now(), async () => {
30003024 const response = await handle(request, server);
30013025 return handedOver && response !== undefined ? withHeader(response, "connection", "close") : response;
3002 }),
3026 });
3027 },
30033028 // A last resort: `handle` answers a throw itself, so it is counted.
30043029 error: (error) => failure(app, error),
30053030 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs