diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-10-16 17:42:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 00:42:15 +0000 |
commit | 458d6278d2835896018086da773fd72b7af8ed66 (patch) | |
tree | d8b5708d49c7d68cf51682b95a56d9710d01df6c /ext/node/polyfills/http.ts | |
parent | 3385d1252e4eae093234d0a075f4a564308ba48e (diff) |
fix(node/http): normalize header names in `ServerResponse` (#26339)
Fixes https://github.com/denoland/deno/issues/26115.
We weren't normalizing the headers to lower case, so code that attempted
to delete the `Content-Length` header (but used a different case) wasn't
actually removing the header.
Diffstat (limited to 'ext/node/polyfills/http.ts')
-rw-r--r-- | ext/node/polyfills/http.ts | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 349caeea6..e117a0ec2 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -72,7 +72,7 @@ import { STATUS_CODES } from "node:_http_server"; import { methods as METHODS } from "node:_http_common"; const { internalRidSymbol } = core; -const { ArrayIsArray } = primordials; +const { ArrayIsArray, StringPrototypeToLowerCase } = primordials; type Chunk = string | Buffer | Uint8Array; @@ -1270,20 +1270,21 @@ export class ServerResponse extends NodeWritable { if (Array.isArray(value)) { this.#hasNonStringHeaders = true; } - this.#headers[name] = value; + this.#headers[StringPrototypeToLowerCase(name)] = value; return this; } appendHeader(name: string, value: string | string[]) { - if (this.#headers[name] === undefined) { + const key = StringPrototypeToLowerCase(name); + if (this.#headers[key] === undefined) { if (Array.isArray(value)) this.#hasNonStringHeaders = true; - this.#headers[name] = value; + this.#headers[key] = value; } else { this.#hasNonStringHeaders = true; - if (!Array.isArray(this.#headers[name])) { - this.#headers[name] = [this.#headers[name]]; + if (!Array.isArray(this.#headers[key])) { + this.#headers[key] = [this.#headers[key]]; } - const header = this.#headers[name]; + const header = this.#headers[key]; if (Array.isArray(value)) { header.push(...value); } else { @@ -1294,10 +1295,10 @@ export class ServerResponse extends NodeWritable { } getHeader(name: string) { - return this.#headers[name]; + return this.#headers[StringPrototypeToLowerCase(name)]; } removeHeader(name: string) { - delete this.#headers[name]; + delete this.#headers[StringPrototypeToLowerCase(name)]; } getHeaderNames() { return Object.keys(this.#headers); |