Comments (9)
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.
from axios.
I would imagine that "full" cookie jar support would:
- respect cookie deletion headers in server response
- respect cookie expiration
- maybe more..?
As for cases where you wouldn't want cookie support:
- Unit testing of http endpoints?
- Deliberately ignoring cookie headers?
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.
from axios.
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.
It seems that axios.interceptors.request
is triggered between the request being made and then
callback being executed. So it doesn't inject the cookie in the request.
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.
from axios.
@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?
from axios.
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.
from axios.
@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
from axios.
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.
from axios.
@andreportela
I'm writed simple example for works with cookie/session in node.js
https://gist.github.com/nzvtrk/ebf494441e36200312faf82ce89de9f2
from axios.
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. π€·ββοΈ
from axios.
Related Issues (20)
- CSRF Token Mismatch HOT 4
- [fatal][nodejs] βError: Unexpected end of formβ after multiple post file formdata, and then hang up after multiple error happening HOT 3
- "Class extends value #<newConstructor> is not a constructor or null" when sending request from node.js 20.12.0
- [0.28.1] options.paramsSerializer as function don't work HOT 2
- vite5+vue3+ts Sending request error SyntaxError: The requested module '/node_modules/.vite/deps/axios.js?v=bc297318' does not provide an export named 'AxiosInstance' HOT 1
- Issue CVEs for vulnerabilities fixed by #6167 and #6163 HOT 1
- How to set localAddress when sending HTTP requests? HOT 2
- API call happening twice, but called once! HOT 3
- RefferenceError: Axios is not defined. HOT 2
- Security vulnerability HOT 2
- postForm's form-data serialization breaks for Blob in Node.js
- Axios stream aborts early during 204 response from prism cli.
- I am getting a error involving CancelToken.js...
- TypeError: Converting circular structure to JSON
- React native Android NETWORK ERROR
- Issue with downloading files larger than a few mbs on Chrome specifically HOT 4
- please expose the formDataToStream for public use
- 100% Upload progress on dev mode only.
- XSRF-TOKEN logic should utilize cookie domain instead of current page domain HOT 1
- Question: Rollup configuration with ESM
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from axios.