Skip to content

Commit

Permalink
Merge pull request #13 from sanny-io/fix-set-cookie-header
Browse files Browse the repository at this point in the history
  • Loading branch information
cuibonobo committed Feb 12, 2024
2 parents e436373 + 5501a1e commit 54beb50
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/index.ts
Expand Up @@ -106,9 +106,20 @@ async function getResponse(
return createError("Network Error", config, "ERR_NETWORK", request);
}

const stageOneHeaders: Record<string, string> = {};
const stageOneHeaders: Record<string, string | string[]> = {};
stageOne.headers.forEach((value, key) => {
stageOneHeaders[key] = value;
// The `Set-Cookie` header is treated as an array of strings (even if there's only 1)
if (key === "set-cookie") {
const cookies = stageOneHeaders[key] as string[] | undefined

if (cookies) {
cookies.push(value);
} else {
stageOneHeaders[key] = [value];
}
} else {
stageOneHeaders[key] = value;
}
});
const headers: any = Object.assign({}, stageOneHeaders as unknown);
const response: AxiosResponse = {
Expand Down

0 comments on commit 54beb50

Please sign in to comment.