Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Cookie, CookieJar, MemoryCookieStore } from 'tough-cookie';
let header = '';
const cb = () => { };
const cookie = Cookie.parse(header)!;
cookie.value = 'somethingdifferent';
header = cookie.toString();
const cookiejar = new CookieJar();
cookiejar.setCookie(cookie, 'http://currentdomain.example.com/path', cb);
// ...
cookiejar.getCookies('http://example.com/otherpath', (err, cookies) => {
// res.headers['cookie'] = cookies.join('; ');
});
// All option are optional.
cookiejar.getCookies('http://example.com/otherpath', {}, () => {});
cookiejar.getCookies('http://example.com/otherpath', {
now: new Date(),
allPaths: true,
return cookies.reduce((resultCookies, cookieStr) => {
let cookie;
if (!isClient) {
if (cookieStr.length > BYTES_PER_COOKIE_LIMIT)
return resultCookies;
cookie = Cookie.parse(cookieStr, { loose: true });
if (!cookie)
return resultCookies;
}
else
cookie = cookieStr;
// NOTE: If cookie.domain and url hostname are equal to localhost/127.0.0.1,
// we should remove 'Domain=...' form cookieStr (GH-1491)
if (Cookies._hasLocalhostDomain(cookie) && (isClient || parseUrl(url).hostname === cookie.domain))
cookie.domain = '';
const parsedCookie = this._cookieJar.setCookieSync(cookie, url, {
http: !isClient,
ignoreError: true,
loose: true
function parse(str) {
var strict = true // strict RFC conformance
return Cookie.parse(str, strict)
}
function replyCookies(setCookies, prev) {
if (!setCookies) return prev;
var cookies;
if (Array.isArray(setCookies)) cookies = setCookies.map(Cookie.parse);
else cookies = [Cookie.parse(setCookies)];
cookies = cookies.map(function(cookie) {
return cookie.cookieString();
});
if (prev) prev.split('; ').forEach(function(str) {
if (cookies.indexOf(str) < 0) cookies.unshift(str);
});
return cookies.join('; ');
}
renderRow (h, i) {
let cookie = null;
try {
cookie = h ? Cookie.parse(h.value || '') : null;
} catch (err) {
console.warn('Failed to parse set-cookie header', h);
}
const blank = <span>--</span>;
return (
{cookie ? cookie.key : blank}
{cookie ? cookie.value : blank}
);
}
renderRow(h, i) {
let cookie = null;
try {
cookie = h ? Cookie.parse(h.value || '') : null;
} catch (err) {
console.warn('Failed to parse set-cookie header', h);
}
const blank = <span>--</span>;
return (
{cookie ? cookie.key : blank}
{cookie ? cookie.value : blank}
);
}
.map(function(c) {
var cookie;
if (typeof c === 'string')
cookie = Cookie.parse(c);
else
cookie = new Cookie(c);
cookie.domain = cookie.domain || purl.hostname;
cookie.path = cookie.path || '/';
return cookie;
})
.map(helpers.serializeCookie);
_isValid () {
try {
const cookie = Cookie.parse(this._input.value);
return !!(cookie && cookie.domain);
} catch (e) {
return false;
}
}