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
NodeJS - Cookie Jar Support #48
Comments
@nicholasrobinson you say that using interceptors provides "trivial cookie support". What is missing for full support? Also, is there a case where you wouldn't want cookie support for node? Specifically, does there need to be an option, or just always manage cookies for requests with node? |
I would imagine that "full" cookie jar support would:
As for cases where you wouldn't want cookie support:
IMO there should be a flag to disable cookie jar support. More generally speaking though it is useful to be able to emulate browser functionality in automated testing scenarios. |
In Node, you may also wish to use different cookie jars depending on which sites you are accessing. A default cookie jar could be defined, but an alternate used on specific requests. Just leverage the existing merging of options that Axios already provides. |
I was recently trying to do just that (add trivial cookie support) and I've used the code sample posted by @nicholasrobinson. Unfortunately I couldn't make it work like that. I made it work by manually capturing the cookie on the first server response and then manually injecting the cookie into the following requests (which is ugly) like this function getCookie(response) {
return response.headers['set-cookie'];
}
function makeRequestWithGivenCookie(cookie) {
return axios.get('/',{headers: {"Cookie": cookie}});
} Am I missing something here? BTW axios is great! Cookie support would really be an awesome feature. |
Please, take a look at #206 (comment) var axios = require('axios');
var axiosCookieJar = require('axios-cookiejar'); // It does not exist yet
axiosCookieJar(axios, options);
// Or
var instance = axios.create(...);
axiosCookieJar(instance, options); @damoclark, you could do that easily with the kind of plugin that I described, using different axios instances for those specific requests you talked about. |
would definitely like to see cookies/persistent sessions support in axios. A third party module is a great addition but there's no guarantee on it's maintainability in the future. |
@lirantal we're rather short maintaining the functionality Axios has at the moment so adding things that can be implemented in plugins won't help that. I'm closing this issue as it won't be implemented in core and there's a library that implements this in ECOSYSTEM.md |
@andreportela https://gist.github.com/nzvtrk/ebf494441e36200312faf82ce89de9f2 |
Hi @nzvtrk I didn't have the time to take a look at it. But thanks for sharing! 😃 It may be useful to a lot of people that end up here. It has been a long time since I moved on. But it seems that this feature is already implemented on a lib. Maybe I would rather just use it. 🤷♂️ |
axios running on NodeJS does not provide Cookie jar support natively. Ideally the library would either provide built in cookie jar functionality or easily accommodate existing cookie jar libraries.
The Request API could be modified to support the following options:
or
where
Note:
Trivial cookie support using tough-cookie can be added by leveraging interceptors:
The text was updated successfully, but these errors were encountered: