-
Notifications
You must be signed in to change notification settings - Fork 26
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
refactor: cookie support via interceptors #216
Conversation
Removes axios-cookiejar-support dependency. Adds cookie-support.ts for providing interceptors to interact with tough-cookie. Updates cookiejar tests. Signed-off-by: Rich Ellis <ricellis@users.noreply.github.com>
f3b08d9
to
994a25c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great overall! Thanks for the contribution. I just have one comment about some async
code. Might not need to change but wanted to check your intentions
lib/cookie-support.ts
Outdated
if (cookies) { | ||
logger.debug(`CookieInterceptor: setting cookies in jar for URL ${response.config.url}.`); | ||
cookies.forEach(async (cookie: string) => { | ||
await this.cookieJar.setCookie(cookie, response.config.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be some issues with calling async
functions within a forEach
method. Are you intending to call setCookie
sequentially?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you intending to call setCookie sequentially?
Good spot, thanks. My main intention was to ensure that the cookies were written before the interceptor returned the response, such that any requests happening after that response would be able to read the cookies.
I honestly hadn't given a lot of thought to whether writes were happening sequentially or in parallel and I don't know a lot about the safety of parallel writes to asynchronous cookie stores (of which I guess there are potentially many implementations). With that safety in mind and given that it is likely that the cookies are small and there will be only a single cookie in the majority of cases I suspect that there won't be a huge performance penalty from writing sequentially. So I've made an attempt at changing to that in 3bf097b.
605ce50
to
994a25c
Compare
Signed-off-by: Rich Ellis <ricellis@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
🎉 This PR is included in version 4.0.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Attempts to upgrade to axios 1.x (#209/#213) have been impeded by incompatibilities with
axios-cookiejar-support
:Remove axios-cookiejar-support depdenency.
This PR:
axios-cookiejar-support
dependency.cookie-support.ts
for providing axios interceptors to interact withtough-cookie
.Checklist
npm test
passes (tip:npm run lint-fix
can correct most style issues)