diff options
author | 2022-12-01 21:09:43 -0800 | |
---|---|---|
committer | 2022-12-01 21:09:43 -0800 | |
commit | 5854d395259f4084b1d66e9f12b54085f277527e (patch) | |
tree | 3c1c9021a6c2cdb185337e2572f1553ae05fcf0f /test/bun.js/fetch.test.js | |
parent | b4e6ca046291058ed9a1ba7fa4733acbc649f36c (diff) | |
download | bun-5854d395259f4084b1d66e9f12b54085f277527e.tar.gz bun-5854d395259f4084b1d66e9f12b54085f277527e.tar.zst bun-5854d395259f4084b1d66e9f12b54085f277527e.zip |
[fetch] Implement `redirect: "manual"`
Diffstat (limited to 'test/bun.js/fetch.test.js')
-rw-r--r-- | test/bun.js/fetch.test.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/bun.js/fetch.test.js b/test/bun.js/fetch.test.js index a703c955a..519d6bbdd 100644 --- a/test/bun.js/fetch.test.js +++ b/test/bun.js/fetch.test.js @@ -60,6 +60,48 @@ describe("fetch", () => { expect(exampleFixture).toBe(text); }); } + + it(`"redirect: "manual"`, async () => { + const server = Bun.serve({ + port: 4082, + fetch(req) { + return new Response(null, { + status: 302, + headers: { + Location: "https://example.com", + }, + }); + }, + }); + const response = await fetch(`http://${server.hostname}:${server.port}`, { + redirect: "manual", + }); + expect(response.status).toBe(302); + expect(response.headers.get("location")).toBe("https://example.com"); + expect(response.redirected).toBe(true); + server.stop(); + }); + + it(`"redirect: "follow"`, async () => { + const server = Bun.serve({ + port: 4083, + fetch(req) { + return new Response(null, { + status: 302, + headers: { + Location: "https://example.com", + }, + }); + }, + }); + const response = await fetch(`http://${server.hostname}:${server.port}`, { + redirect: "follow", + }); + expect(response.status).toBe(200); + expect(response.headers.get("location")).toBe(null); + expect(response.redirected).toBe(true); + server.stop(); + }); }); it("simultaneous HTTPS fetch", async () => { |