UNPKG

@tunframework/tun

Version:

tun framework for node with typescript

38 lines (37 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._stringifyTunCookie = exports._getRequestCookieByName = void 0; /** * @internal * @see TunContext.getRequestCookie */ 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(); } }); } exports._getRequestCookieByName = _getRequestCookieByName; /** * @internal */ 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(';'); } exports._stringifyTunCookie = _stringifyTunCookie;