Skip to content
Merged
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
28 changes: 28 additions & 0 deletions src/gateway/relay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,32 @@ describe("GatewayRelay against a worker that breaks the protocol", () => {

expect(await pending).toMatchObject({ code: "WORKER_UNREACHABLE", state: "rejected" });
});

it("drops every hop-by-hop and framing header of a worker's relay head, in any case, and keeps an ordinary header, on the response it hands the caller", async () => {
const { connection, relay } = await setup();
const pending = relay.relay(WORKER_ID, call());
const request = await sentFrame(connection, "relay.request");
await openedChannel(connection);

connection.push("relay-head", {
headers: [
["connection", "close"],
["Content-Length", "5"],
["keep-alive", "timeout=5"],
["proxy-authenticate", "Basic realm=worker"],
["proxy-authorization", "Basic worker-secret"],
["te", "trailers"],
["Te", "custom-checksum"],
["trailer", "X-Note"],
["TRANSFER-ENCODING", "chunked"],
["upgrade", "h2c"],
["x-kept", "yes"],
],
requestId: request.id,
status: 200,
});
const response = await pending;

expect([...response.headers.entries()]).toEqual([["x-kept", "yes"]]);
});
});
13 changes: 11 additions & 2 deletions src/gateway/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// channel wait and the wait for the head, and an idle bound covers the response body, which may be a live stream that
// runs as long as someone reads it; the link bounds the channels open to a worker (ADR 0028).

import { isSimlockError, relayHeaderPairs, type AnySimlockError } from "../contract/index.js";
import {
isRelayFramingHeader,
isSimlockError,
relayHeaderPairs,
type AnySimlockError,
} from "../contract/index.js";
import { DispatchError } from "../daemon/dispatch.js";
import { LinkChannelError, type LinkChannel } from "../link/index.js";
import { type Clock, SystemClock, type TimerHandle } from "../ports/index.js";
Expand Down Expand Up @@ -204,7 +209,11 @@ class Exchange {
}
const responseHeaders = new Headers();
try {
for (const [name, value] of headers) responseHeaders.append(name, value);
for (const [name, value] of headers) {
// why: the gateway frames its own response, so a worker's framing headers must not reach the caller.
if (isRelayFramingHeader(name)) continue;
responseHeaders.append(name, value);
}
} catch {
// why: `Headers` refuses a value above U+00FF that the push schema lets through.
this.#invalid();
Expand Down
Loading