Got: Replace tough-cookie

Created on 19 Sep 2019  Â·  9Comments  Â·  Source: sindresorhus/got

What problem are you trying to solve?

I'm back from here. https://github.com/sindresorhus/got/issues/811
It is an issue of tough-cookie library. But the fix is in stale status for several months...

Describe the feature

So I'm thinking it would be really nice if got provides an abstract interface so I can use other cookie store than tough-cookie.

Checklist

  • [x] I have read the documentation and made sure this feature doesn't already exist.
enhancement ✭ help wanted ✭

All 9 comments

Out of curiosity, what other cookie storage would you use?

It is an issue of tough-cookie library. But the fix is in stale status for several months...

https://github.com/salesforce/tough-cookie/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+author%3ARokt33r

You haven't opened such issue. Not to mention that tough-cookie is RFC-compliant.

I think @Rokt33r is referring to https://github.com/salesforce/tough-cookie/pull/130

Ah. In this case I would just open a new PR. The fix is very simple.

So I'm thinking it would be really nice if got provides an abstract interface so I can use other cookie store than tough-cookie.

You just need to pass an object having these and you're good to go:

  • setCookie(cookieOrString, currentUrl, [{options},] cb(err,cookie))
  • getCookieString(currentUrl, [{options},] cb(err,cookies))

https://github.com/sindresorhus/got/blob/f59a5638b93c450dc722848b58b09a44f730a66f/source/request-as-event-emitter.ts#L49-L50

@sindresorhus I'm not using any for now. But if got makes it possible, I would have options to fork tough-cookie or to make another one from the scratch.

@szmarczak I think we need to define cookieJar interface in this package too. Otherwise, I still need to install @types/tough-cookie every time.

Also it would be awesome if the new interface's methods return Promise rather than accepting callback although it should be breaking change...

I think we need to define cookieJar interface in this package too. Otherwise, I still need to install @types/tough-cookie every time.

:+1:

Also it would be awesome if the new interface's methods return Promise rather than accepting callback although it should be breaking change...

I agree. Maybe we'll see these promises in Got v11. Let's stay with the callbacks for now.

@szmarczak It would be nice not to be so tied to tough-cookie. We could maybe support both though. Detect whether the input is tough.CookieJar and if not, have a nicer general interface using promises. ?

have a nicer general interface using promises. ?

cookieJar needs to be an object:

interface CookieJar {
    getCookieString(url: string, callback: (error: Error, cookieHeader: string) => void);
    setCookie(rawCookie: string, url: string, callback: (error: Error, result: unknown) => void);
}

we just need to detect if it's a Promise or is it a callback-style function :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dominusmars picture dominusmars  Â·  3Comments

carvallegro picture carvallegro  Â·  4Comments

alanzhaonys picture alanzhaonys  Â·  4Comments

khizarsonu picture khizarsonu  Â·  3Comments

tkoelpin picture tkoelpin  Â·  3Comments