Skip to content

Commit

Permalink
fix: handle duplicate Set-Cookie headers from Icinga (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rentallect authored Nov 1, 2023
1 parent 365af1d commit e3bcafc
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/context/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2043,11 +2043,8 @@ class ZitiContext extends EventEmitter {
let expires;
let httpOnly = false;

// let zitiCookies = await ls.getWithExpiry(zitiConstants.get().ZITI_COOKIES);
// if (isNull(zitiCookies)) {
// zitiCookies = {}
// }

let condensedCookieArray = new Map();

for (let i = 0; i < cookieArray.length; i++) {

let cookie = cookieArray[i];
Expand All @@ -2058,25 +2055,25 @@ class ZitiContext extends EventEmitter {
let parts = value.split(";");
for (let j = 0; j < parts.length; j++) {
let part = parts[j].trim();
if ( part.startsWith("Path") ) {
if ( part.trim().toLowerCase().startsWith("path") ) {
cookiePath = part.substring(part.indexOf("=") + 1);
}
else if ( part.startsWith("Expires") ) {
else if ( part.trim().toLowerCase().startsWith("expires") ) {
expires = new Date( part.substring(part.indexOf("=") + 1) );
}
else if ( part.startsWith("HttpOnly") ) {
httpOnly = true;
}
}


// zitiCookies[name] = cookie_value;

// await ls.setWithExpiry(zitiConstants.get().ZITI_COOKIES, zitiCookies, new Date(8640000000000000));

Cookies.set(name, cookie_value, { expires: expires, path: cookiePath});
condensedCookieArray.set(name, {name: name, cookie_value: cookie_value, expires: expires, cookiePath: cookiePath});
}
}

function setCondensedCookies(value, key) {
Cookies.set(value.name, value.cookie_value, { expires: value.expires, path: value.cookiePath});
}
condensedCookieArray.forEach(setCondensedCookies);
}
}
}
Expand Down

0 comments on commit e3bcafc

Please sign in to comment.