-
Notifications
You must be signed in to change notification settings - Fork 251
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
Clone Cookie Jar / Get all Cookies from Cookie Store #29
Comments
+1 I need to be able to serialize a cookie jar and recreate it later in another server. Is this possible? Getting all the cookies from a jar is a start.. Right now I'm trying to inspect the jar.store property, but without much success. |
After some time trying, I came up with these three functions: var Cookie = tough.Cookie,
CookieJar = tough.CookieJar;
function cookieJarToJSON(jar){
return JSON.stringify(jar.store.idx);
}
function cookieJarFromJSON(json){
var idx = JSON.parse(json),
jar = new CookieJar;
for(var i in idx){
for(var o in idx[i]){
for(var cookieKey in idx[i][o]){
var c = idx[i][o][cookieKey];
jar.setCookieSync(new Cookie(c).toString(), {hostname: c.domain, path: c.path});
}
}
}
return jar;
}
function cookieJarClone(jar){
return cookieJarFromJSON(cookieJarToJSON(jar));
} If you want a clone of a jar, just do |
Seems can be implemented in context of #24 |
PR is welcome, BTW |
I'm going to try implement a jar-to-JSON feature today. |
Fixed via #42, published as v2.0.0 |
Based on a discussion here request/request#1458
We have a situation where we want to clone a CookieJar. I'm not completely clear on the "why" we want to do this, but we started to explore the "how". I'm wondering if anyone here has any recommendation on how to clone a CookieJar or at least how to get all the cookies from a CookieJar so we can manually clone it.
The text was updated successfully, but these errors were encountered: