20 lines
881 B
TypeScript
20 lines
881 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { defaultGatewayHostname, gatewayProxyHeaders } from "../src/gateway.ts";
|
|
|
|
test("gateway uses platform-safe hostname defaults", () => {
|
|
expect(defaultGatewayHostname("development")).toBe("127.0.0.1");
|
|
expect(defaultGatewayHostname("production")).toBe("0.0.0.0");
|
|
});
|
|
|
|
test("gateway disables compression for its internal proxy hop", () => {
|
|
const request = new Request("http://localhost:3000/path", {
|
|
headers: { host: "web.localhost:3000", "accept-encoding": "gzip, deflate" },
|
|
});
|
|
const headers = gatewayProxyHeaders(request, new URL(request.url), "127.0.0.1", true);
|
|
|
|
expect(headers.get("accept-encoding")).toBe("identity");
|
|
expect(headers.get("x-forwarded-host")).toBe("web.localhost:3000");
|
|
expect(headers.get("x-forwarded-proto")).toBe("http");
|
|
expect(headers.get("x-forwarded-for")).toBe("127.0.0.1");
|
|
});
|