How to use the tough-cookie.MemoryCookieStore 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 DefinitelyTyped / DefinitelyTyped / types / tough-cookie / tough-cookie-tests.ts View on Github external
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,
}, () => {});

CookieJar.deserializeSync("test cookie with store", new MemoryCookieStore());
CookieJar.deserializeSync("test cookie");
github yeutech-lab / test-polyfill / src / index.js View on Github external
export function polyfill(options) {
  const opts = { ...defaultOptions, ...options };
  let root = null;
  try {
    root = window || global;
  } catch (e) {
    root = global;
  }
  if (opts.isomorphicFetch) {
    const Tough = require('tough-cookie');
    const Store = new Tough.MemoryCookieStore();

    const rejectPublicSuffixes = false; // See https://github.com/salesforce/tough-cookie#cookiejarstoreoptions
    const cookieJar = new Tough.CookieJar(Store, rejectPublicSuffixes);
    const fetch = require('fetch-cookie')(require('@yeutech-lab/isomorphic-fetch'), cookieJar);
    root.fetch = fetch;
    root.cookieJar = cookieJar;
  }

  if (opts.fetch && !opts.isomorphicFetch) {
    require('whatwg-fetch');
    root.fetchMock = require('fetch-mock');
  }

  if (opts.localStorage && !root.localStorage) {
    root.localStorage = require('localStorage');
  }