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)
- An error occurred when using the system proxy environment in Linux
- Unable to get the value of Content-Type
- Axios Preventing Constant Contact from running checklist
- Axios request automatically fired a second time after a delay
- Axios sends boundary text even when form data is empty HOT 3
- Progress event does not have lengthComputable property
- test cases fails when the interceptor header exceeds 10 characters
- Form data key of "x-amz-security-token" changes from string key to object {x: { amz: {security: { token: <value> } } } }
- What is the correct version guide of Axios? HOT 2
- SSRF Vulnerability Arising from Axios URL Parsing HOT 3
- Why is the headers attribute of InternalAxiosRequestConfig mandatory?
- Security Vulnerability from follow-redirects HOT 1
- axios V0.28.0 Uncaught ReferenceError: req is not defined at AbortSignal.onCanceled HOT 7
- Network Error in React Native HOT 5
- Axios lib gets detected as a trojan HOT 3
- Can't find variable: axios error thrown on older browser (since v.1.6.8) HOT 1
- Invalid package attestation - 1.6.8 HOT 4
- Axios calculating wrong Content-Length HOT 2
- Information Exposure due to the handling of the Proxy-Authorization header across hosts HOT 1
- The interface has a return value, but the axios report response is undefined
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.