How to use the tough-cookie.CookieJar.fromJSON function in tough-cookie

To help you get started, we’ve selected a few tough-cookie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Kong / insomnia / packages / insomnia-cookies / index.js View on Github external
module.exports.jarFromCookies = function(cookies) {
  let jar;

  try {
    // For some reason, fromJSON modifies `cookies`. Create a copy first
    // just to be sure
    const copy = JSON.stringify({ cookies });
    jar = CookieJar.fromJSON(copy);
  } catch (e) {
    console.log('[cookies] Failed to initialize cookie jar', e);
    jar = new CookieJar();
  }

  jar.rejectPublicSuffixes = false;
  jar.looseMode = true;

  return jar;
};