From 416df1e895d6dad4ac90814ef7c41e14c03696d0 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 21 Jun 2024 19:21:59 +0530 Subject: fix(ext/node): add ServerResponse#appendHeader (#24216) --- ext/node/polyfills/http.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ext') diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index c6c112a50..f009d8a9e 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -1420,6 +1420,26 @@ export class ServerResponse extends NodeWritable { return this; } + appendHeader(name: string, value: string | string[]) { + if (Array.isArray(value)) { + this.#hasNonStringHeaders = true; + } + if (this.#headers[name] === undefined) { + this.#headers[name] = value; + } else { + if (!Array.isArray(this.#headers[name])) { + this.#headers[name] = [this.#headers[name]]; + } + const header = this.#headers[name]; + if (Array.isArray(value)) { + header.push(...value); + } else { + header.push(value); + } + } + return this; + } + getHeader(name: string) { return this.#headers[name]; } -- cgit v1.2.3