(status: number, method: string)
| 1415 | // method, 301 demotes a non-GET, and 308 replays method and body untouched. |
| 1416 | it("applies the right method semantics per redirect status", async () => { |
| 1417 | const run = async (status: number, method: string) => { |
| 1418 | const seen: Array<{ method: string; hasBody: boolean }> = []; |
| 1419 | const underlying: typeof globalThis.fetch = async (input, init) => { |
| 1420 | seen.push({ |
| 1421 | method: init?.method ?? "GET", |
| 1422 | hasBody: init?.body !== undefined && init?.body !== null, |
| 1423 | }); |
| 1424 | if (String(input) === "https://api.example/start") { |
| 1425 | return new Response(null, { status, headers: { location: "/moved" } }); |
| 1426 | } |
| 1427 | return new Response("ok", { status: 200 }); |
| 1428 | }; |
| 1429 | const hostedFetch = makeHostedFetch({ fetch: underlying, resolveHostname: publicResolver }); |
| 1430 | await hostedFetch( |
| 1431 | "https://api.example/start", |
| 1432 | method === "HEAD" ? { method } : { method, body: "secret=1" }, |
| 1433 | ); |
| 1434 | return seen[1]; |
| 1435 | }; |
| 1436 | |
| 1437 | expect(await run(303, "POST")).toMatchObject({ method: "GET", hasBody: false }); |
| 1438 | expect(await run(301, "POST")).toMatchObject({ method: "GET", hasBody: false }); |
no test coverage detected