-
-
Notifications
You must be signed in to change notification settings - Fork 533
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
fix: implement cookie persistence using tough-cookie
#2206
Conversation
} | ||
const cookiesFromStore = Object.fromEntries( | ||
cookieStore | ||
.getCookiesSync(request.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.
The tough-cookie
package implements specification-compliant way of returning matching cookies for the given URL. It's maintained and well-used. I see no reason for us to rely on @mswjs/cookies
anymore.
// in the HeadersInit. This is later used to store these cookies | ||
// in cookie jar and return the right cookies in the "cookies" | ||
// response resolver argument. | ||
Object.defineProperty(response, kSetCookie, { |
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.
I would love to store the cookies here directly but tough-cookie
needs a URL to associate the cookies with. response.url
is not always defined (this may be easier to solve). I don't like introducing a symbol just to pass the data around.
tough-cookie
Released: v2.3.3 🎉This has been released in v2.3.3! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
HttpOnly
cookies are not exposed to thecookies
argument of the response resolver.This is a rework of the request/response cookie handling. Since v2, I believe the previous logic has become obsolete. We are forwarding the mocked response cookies to the
document.cookie
but we won't be able to read them back if those cookies are not exposed to JavaScript (likeHttpOnly
cookies). Neither would we be able to read them back from theresponse.headers.get('set-cookie')
because that's a forbidden header field.In this rework, I'm removing
@mswjs/cookies
and introducingtough-cookie
and itsCookieJar
class to get cookie filtering and, eventually, persistence (has to be implemented separately through a customStore
).Roadmap
require
leaking throughtough-cookie
(is it CJS-only?)@bundled-es-modules/tough-cookie
localStorage
so they persist across page refreshes.