Skip to content

Commit

Permalink
Handle multiple set-cookie headers from fetch API Headers object (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarnes authored Aug 8, 2023
1 parent e6cd6a1 commit 8f48d77
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/connect-node/src/node-universal-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(headersInit)) {
const k = key.toLowerCase();
o[k] = value;
append(key, value);
}
}
return o;
Expand Down

0 comments on commit 8f48d77

Please sign in to comment.