How to use the tough-cookie.Cookie.parse 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
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,
github DevExpress / testcafe-hammerhead / src / session / cookies.ts View on Github external
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
github eldargab / agent-next / lib / middlewares / cookies.js View on Github external
function parse(str) {
  var strict = true // strict RFC conformance
  return Cookie.parse(str, strict)
}
github kapouer / url-inspector / lib / inspector.js View on Github external
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('; ');
}
github Kong / insomnia / app / ui / components / viewers / response-cookies-viewer.js View on Github external
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}
      
    );
  }
github Kong / insomnia / packages / insomnia-app / app / ui / components / viewers / response-cookies-viewer.js View on Github external
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}
      
    );
  }
github medialab / sandcrawler / src / engines / phantom.js View on Github external
.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);
github Kong / insomnia / app / ui / components / cookie-input.js View on Github external
_isValid () {
    try {
      const cookie = Cookie.parse(this._input.value);
      return !!(cookie && cookie.domain);
    } catch (e) {
      return false;
    }
  }