Skip to content

tough-cookie 4.0.0 integration broken #1131

@sneusse

Description

@sneusse

Since this commit in tough-cookie (salesforce/tough-cookie@d5d6f79#diff-d721bcd439ec1bdd00213161a426ebd8 , code below) the following line to check the cookieJar won't work anymore:

if (setCookie.length === 4 && getCookieString.length === 0) {

as the code in tough-cookie patches the prototype so the length of all the methods will always return 0.

https://github.com/salesforce/tough-cookie/blob/2524513d49b7fab37639dfb7c6b87994c2bd7791/lib/cookie.js#L1618-L1629

The workaround provided here #1082 will also work here.

-- one more workaround:

function proxy(org, proxifier) {
  return new Proxy(proxifier(org), {
    get: (obj, prop) => (prop in obj ? obj[prop] : org[prop])
  });
}

const cookies = proxy(new CookieJar(), obj => {
  return {
    setCookie: async (rawCookie, url) => obj.setCookie(rawCookie, url, console.log),
    getCookieString: async url => obj.getCookieString(url)
  };
});

const resp = await got("https://google.com", { cookieJar: cookies });

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething does not work as it shouldenhancementThis change will extend Got features✭ help wanted ✭

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions