From 61d548c7bff872d53417845d5219dc75cb7e5ecb Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 8 May 2022 01:12:46 -0700 Subject: [bun.js] Fix bug with headers not being sent in `fetch` --- integration/bunjs-only-snippets/serve.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'integration/bunjs-only-snippets/serve.test.ts') diff --git a/integration/bunjs-only-snippets/serve.test.ts b/integration/bunjs-only-snippets/serve.test.ts index 323caf1f8..653454cc3 100644 --- a/integration/bunjs-only-snippets/serve.test.ts +++ b/integration/bunjs-only-snippets/serve.test.ts @@ -32,6 +32,28 @@ it("should work for a file", async () => { server.stop(); }); +it("fetch should work with headers", async () => { + const fixture = resolve(import.meta.dir, "./fetch.js.txt"); + + const server = serve({ + port: port++, + fetch(req) { + if (req.headers.get("X-Foo") !== "bar") { + return new Response("X-Foo header not set", { status: 500 }); + } + return new Response(file(fixture)); + }, + }); + const response = await fetch(`http://localhost:${server.port}`, { + headers: { + "X-Foo": "bar", + }, + }); + + expect(response.status).toBe(200); + server.stop(); +}); + var count = 200; it(`should work for a file ${count} times`, async () => { const fixture = resolve(import.meta.dir, "./fetch.js.txt"); -- cgit v1.2.3