Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tough-cookie 4.0.0 integration broken #1131

Closed
sneusse opened this issue Mar 24, 2020 · 2 comments
Closed

tough-cookie 4.0.0 integration broken #1131

sneusse opened this issue Mar 24, 2020 · 2 comments
Labels
bug Something does not work as it should enhancement This change will extend Got features ✭ help wanted ✭

Comments

@sneusse
Copy link

sneusse commented Mar 24, 2020

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 });
@sneusse sneusse changed the title Tough 4.0.0 cookie integration broken tough-cookie 4.0.0 integration broken Mar 24, 2020
@szmarczak szmarczak added bug Something does not work as it should enhancement This change will extend Got features ✭ help wanted ✭ labels Mar 24, 2020
@szmarczak
Copy link
Collaborator

Fixed in 407d597

@szmarczak szmarczak reopened this Apr 15, 2020
@szmarczak
Copy link
Collaborator

Fixed in 9eb8407

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something does not work as it should enhancement This change will extend Got features ✭ help wanted ✭
Projects
None yet
Development

No branches or pull requests

2 participants