diff options
-rw-r--r-- | src/bun.js/bindings/webcore/JSFetchHeaders.cpp | 2 | ||||
-rw-r--r-- | test/bun.js/fetch_headers.test.js | 12 | ||||
-rw-r--r-- | test/bun.js/node-http.test.ts | 15 |
3 files changed, 28 insertions, 1 deletions
diff --git a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp index 53e104152..3d1b6dbef 100644 --- a/src/bun.js/bindings/webcore/JSFetchHeaders.cpp +++ b/src/bun.js/bindings/webcore/JSFetchHeaders.cpp @@ -450,7 +450,7 @@ static inline JSC::EncodedJSValue jsFetchHeadersPrototypeFunction_toJSONBody(JSC for (auto it = vec.begin(); it != vec.end(); ++it) { auto& name = it->key; auto& value = it->value; - obj->putDirect(vm, Identifier::fromString(vm, name), jsString(vm, value), 0); + obj->putDirect(vm, Identifier::fromString(vm, WTFMove(name.convertToASCIILowercase())), jsString(vm, value), 0); } } diff --git a/test/bun.js/fetch_headers.test.js b/test/bun.js/fetch_headers.test.js index 2e5b9fa52..cd2786c08 100644 --- a/test/bun.js/fetch_headers.test.js +++ b/test/bun.js/fetch_headers.test.js @@ -46,6 +46,18 @@ describe("Headers", async () => { // This would hang expect(await fetchContent({ "x-test": origString })).toBe(origString); }); + + describe("toJSON()", () => { + it("should provide lowercase header names", () => { + const headers1 = new Headers({ "X-Test": "yep", "Content-Type": "application/json" }); + expect(headers1.toJSON()).toEqual({ "x-test": "yep", "content-type": "application/json" }); + + const headers2 = new Headers(); + headers2.append("X-Test", "yep"); + headers2.append("Content-Type", "application/json"); + expect(headers2.toJSON()).toEqual({ "x-test": "yep", "content-type": "application/json" }); + }); + }); }); async function fetchContent(headers) { diff --git a/test/bun.js/node-http.test.ts b/test/bun.js/node-http.test.ts index e0964edb0..619d8cb35 100644 --- a/test/bun.js/node-http.test.ts +++ b/test/bun.js/node-http.test.ts @@ -101,6 +101,11 @@ describe("node:http", () => { res.end("Not Found"); return; } + if (reqUrl.pathname === "/lowerCaseHeaders") { + res.writeHead(200, { "content-type": "text/plain", "X-Custom-Header": "custom_value" }); + res.end("Hello World"); + return; + } if (reqUrl.pathname.includes("timeout")) { if (timer) clearTimeout(timer); timer = setTimeout(() => { @@ -426,6 +431,16 @@ describe("node:http", () => { req.end(); } }); + + it("should return response with lowercase headers", done => { + const req = request(`http://localhost:${serverPort}/lowerCaseHeaders`, res => { + console.log(res.headers); + expect(res.headers["content-type"]).toBe("text/plain"); + expect(res.headers["x-custom-header"]).toBe("custom_value"); + done(); + }); + req.end(); + }); }); describe("signal", () => { |