Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vickymeenakshisundaram
Copy link

Setup setCookie and getCookie modules
Resolves MWPW-175571

if (httpOnly) cookieString += `; HttpOnly`;
if (sameSite) cookieString += `; SameSite=${sameSite}`;

const key = Object.keys(headers).find(k => k.toLowerCase() === 'set-cookie') || 'set-cookie';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to to iterate all the headers every time? Why not do

const existing = headers['Set-Cookie'] ?? headers['set-cookie'];

}

export const getCookie = (headers: Headers) => (name: string): Cookie | undefined => {
const cookieKey = Object.keys(headers).find(k => k.toLowerCase() === 'cookie');
Copy link
Collaborator

@sharmrj sharmrj Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, instead of iterating through the headers, couldn't we do const cookies = headers['Cookie'] ?? headers ['cookie'];

Comment on lines +73 to +75
const cookieString = headers[cookieKey].join('; ');
const cookieParts = cookieString.split(';').map(c => c.trim());

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why join only to immediately split again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants