Skip to content

Commit

Permalink
fix(node/http): casing ignored in ServerResponse.hasHeader() (#27105)
Browse files Browse the repository at this point in the history
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 #27101
  • Loading branch information
marvinhagemeister authored Nov 27, 2024
1 parent 93adf37 commit 9bc36aa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/node/polyfills/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions tests/unit_node/http_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ Deno.test("[node/http] ServerResponse header names case insensitive", async () =
const { promise, resolve } = Promise.withResolvers<void>();
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"));
Expand Down

0 comments on commit 9bc36aa

Please sign in to comment.