This commit is contained in:
Flummi 2025-03-19 10:44:45 +01:00
parent a8a8701739
commit 1b75e89ca4
2 changed files with 8 additions and 4 deletions

@ -7,11 +7,14 @@ export default class CookieManager {
headers?.forEach(header => {
const [cookiePart, ...attributes] = header.split(';').map(part => part.trim());
const [name, value] = cookiePart.split('=');
const cookie = { value: value || "", domain };
const cookie = { value: value || "" };
attributes.forEach(attr => {
const [key, val] = attr.split('=');
const lowerKey = key.toLowerCase();
switch (lowerKey) {
case 'domain':
cookie.domain = val;
break;
case 'path':
cookie.path = val;
break;
@ -38,7 +41,7 @@ export default class CookieManager {
format(domain) {
this.cleanupExpiredCookies();
return Object.entries(this.cookies[domain] || {})
.map(([key, value]) => `${key}=${value.value}`)
.map(([key, value]) => `${key}=${value.value.toString()}`)
.join('; ');
}
getCookies(domain) {

@ -30,11 +30,12 @@ export default class CookieManager {
const [cookiePart, ...attributes] = header.split(';').map(part => part.trim());
const [name, value] = cookiePart.split('=');
const cookie: Cookie = { value: value || "", domain };
const cookie: Cookie = { value: value || "" };
attributes.forEach(attr => {
const [key, val] = attr.split('=');
const lowerKey = key.toLowerCase();
switch(lowerKey) {
case 'domain': cookie.domain = val; break;
case 'path': cookie.path = val; break;
case 'expires': cookie.expires = val ? new Date(val) : undefined; break;
case 'max-age': cookie.maxAge = parseInt(val, 10); break;
@ -51,7 +52,7 @@ export default class CookieManager {
format(domain: string): string {
this.cleanupExpiredCookies();
return Object.entries(this.cookies[domain] || {})
.map(([key, value]) => `${key}=${value.value}`)
.map(([key, value]) => `${key}=${value.value.toString()}`)
.join('; ');
}