Skip to content

Commit 96ad775

Browse files
committed
add header merging tests with and without redirect
1 parent 124a78d commit 96ad775

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

apps/tests/src/e2e/api-call.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,18 @@ test.describe("api calls", () => {
55
const response = await fetch("http://localhost:3000/api/text-plain");
66
expect(await response.text()).toBe("test");
77
});
8+
9+
test("should include headers from both event and returned request", async () => {
10+
const okResp = await fetch("http://localhost:3000/api/header-merging?status=ok");
11+
expect(okResp.headers.get("Set-Cookie")).toBeTruthy();
12+
expect(okResp.headers.get("x-event-header")).toBe("value");
13+
expect(okResp.headers.get("x-return-header")).toBe("value");
14+
expect(okResp.headers.get("x-shared-header")).toBe("event");
15+
16+
const redirectResp = await fetch("http://localhost:3000/api/header-merging?status=redirect", { redirect: "manual" });
17+
expect(redirectResp.headers.get("Set-Cookie")).toBeTruthy();
18+
expect(redirectResp.headers.get("x-event-header")).toBe("value");
19+
expect(redirectResp.headers.get("x-return-header")).toBe("value");
20+
expect(redirectResp.headers.get("x-shared-header")).toBe("event");
21+
})
822
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { getRequestURL, setHeader, useSession } from "@solidjs/start/http";
2+
3+
export async function GET() {
4+
const url = getRequestURL();
5+
6+
const s = await useSession({ password: "0".repeat(32) });
7+
await s.update(d => ({count: (d.count || 0) + 1}))
8+
9+
setHeader("x-event-header", "value");
10+
setHeader("x-shared-header", "event");
11+
12+
if(url.searchParams.get("status") === "redirect") {
13+
return new Response(null, {
14+
status: 301,
15+
headers: {
16+
location: "http://::/abc",
17+
"x-return-header": "value",
18+
"x-shared-header": "return"
19+
}
20+
})
21+
} else {
22+
return new Response(null, {
23+
headers: {
24+
"x-return-header": "value",
25+
"x-shared-header": "return"
26+
}
27+
})
28+
}
29+
}

0 commit comments

Comments
 (0)