From d84f79bcc16d4e748c8a9400ea1cdb03d7f963fb Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 2 Dec 2022 07:40:22 -0800 Subject: [fetch] Implement `Headers#getAll` and `Headers#getSetCookie()` This matches Deno's behavior (get() combines, iterator preserves the order, set and append combine), but implements both the Cloudflare Workers `getAll()` and the potential standard `getSetCookie` function. The rationale for choosing both is to better support libraries which check for `getAll` and also because `getSetCookie` seems a little confusing (names are hard) This also makes `.toJSON` and JSON.stringify return an array for `Set-Cookie` --- test/bun.js/serve.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/bun.js') diff --git a/test/bun.js/serve.test.ts b/test/bun.js/serve.test.ts index 91b57a738..6e5a0030a 100644 --- a/test/bun.js/serve.test.ts +++ b/test/bun.js/serve.test.ts @@ -599,6 +599,31 @@ it("should support reloading", async () => { server.stop(); }); +it("should support multiple Set-Cookie headers", async () => { + const server = serve({ + port: port++, + fetch(req) { + return new Response("hello", { + headers: [ + ["Another-Header", "1"], + ["Set-Cookie", "foo=bar"], + ["Set-Cookie", "baz=qux"], + ], + }); + }, + }); + + const response = await fetch(`http://${server.hostname}:${server.port}`); + server.stop(); + + expect(response.headers.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]); + expect(response.headers.getSetCookie()).toEqual(["foo=bar", "baz=qux"]); + + const cloned = response.clone().headers; + expect(cloned.getAll("Set-Cookie")).toEqual(["foo=bar", "baz=qux"]); + expect(cloned.getSetCookie()).toEqual(["foo=bar", "baz=qux"]); +}); + describe("status code text", () => { const fixture = { 200: "OK", -- cgit v1.2.3