@tunframework/tun
Version:
tun framework for node with typescript
33 lines (32 loc) • 974 B
JavaScript
/**
* @internal
* @see TunContext.getRequestCookie
*/
export function _getRequestCookieByName(request, name) {
const cookies = request.headers.cookie;
if (!cookies) {
return undefined;
}
return cookies.split(';').find((cookie) => {
const parts = cookie.split('=');
if (parts[0].trim() === name) {
return (parts[1] || '').trim();
}
});
}
/**
* @internal
*/
export function _stringifyTunCookie(tunCookie) {
return [
`${tunCookie.name}=${tunCookie.value}`,
tunCookie.domain ? `domain=${tunCookie.domain}` : '',
tunCookie.path ? `path=${tunCookie.path}` : '',
tunCookie.maxAge ? `maxAge=${tunCookie.maxAge}` : '',
tunCookie.expires ? `maxAge=${tunCookie.expires.toUTCString()}` : '',
tunCookie.httpOnly ? `httpOnly` : '',
tunCookie.secure ? `secure` : ''
]
.filter((item) => !!item)
.join(';');
}