1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

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
This commit is contained in:
Marvin Hagemeister 2024-11-27 17:56:13 +01:00 committed by GitHub
parent 93adf37bdf
commit 9bc36aa79b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View file

@ -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 (

View file

@ -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"));