From 9edce4db7782fcf6be85330d7062c5dfa18332dd Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 27 Nov 2024 17:56:13 +0100 Subject: [PATCH] fix(node/http): casing ignored in ServerResponse.hasHeader() (#27105) We didn't respect casing when checking if a HTTP header is present in Node's `ServerResponse.hasHeader()`. This lead to us returning incorrect results when the header was present. Koa assumed that the `Content-Type` header wasn't present when it actually was and defaulted to a different `Content-Type` value. Fixes https://github.com/denoland/deno/issues/27101 --- ext/node/polyfills/http.ts | 2 +- tests/unit_node/http_test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 9a920adeee..948a3527bd 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1409,7 +1409,7 @@ ServerResponse.prototype.hasHeader = function ( this: ServerResponse, name: string, ) { - return Object.hasOwn(this._headers, name); + return Object.hasOwn(this._headers, StringPrototypeToLowerCase(name)); }; ServerResponse.prototype.writeHead = function ( diff --git a/tests/unit_node/http_test.ts b/tests/unit_node/http_test.ts index 2b3b8f509f..31ac6bee25 100644 --- a/tests/unit_node/http_test.ts +++ b/tests/unit_node/http_test.ts @@ -1151,6 +1151,7 @@ Deno.test("[node/http] ServerResponse header names case insensitive", async () = const { promise, resolve } = Promise.withResolvers(); const server = http.createServer((_req, res) => { res.setHeader("Content-Length", "12345"); + assert(res.hasHeader("Content-Length")); res.removeHeader("content-length"); assertEquals(res.getHeader("Content-Length"), undefined); assert(!res.hasHeader("Content-Length"));