diff --git a/packages/connect-node/src/node-universal-header.ts b/packages/connect-node/src/node-universal-header.ts index 5a130f052..a0d1e5191 100644 --- a/packages/connect-node/src/node-universal-header.ts +++ b/packages/connect-node/src/node-universal-header.ts @@ -71,22 +71,30 @@ export function webHeaderToNodeHeaders( return undefined; } const o = Object.create(null) as http.OutgoingHttpHeaders; + const append = (key: string, value: string): void => { + key = key.toLowerCase(); + const existing = o[key]; + if (typeof existing == "string") { + o[key] = [existing, value]; + } else if (Array.isArray(existing)) { + existing.push(value); + } else { + o[key] = value; + } + }; if (Array.isArray(headersInit)) { for (const [key, value] of headersInit) { - const k = key.toLowerCase(); - o[k] = value; + append(key, value); } } else if ("forEach" in headersInit) { if (typeof headersInit.forEach == "function") { headersInit.forEach((value, key) => { - const k = key.toLowerCase(); - o[k] = value; + append(key, value); }); } } else { for (const [key, value] of Object.entries(headersInit)) { - const k = key.toLowerCase(); - o[k] = value; + append(key, value); } } return o;