2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-15 11:59:42 +03:00

feat(withXSRFToken): added withXSRFToken option as a workaround to achieve the old withCredentials behavior; (#6046)

This commit is contained in:
Dmitriy Mozgovoy
2023-11-14 15:38:25 +02:00
committed by GitHub
parent 7009715369
commit cff996779b
8 changed files with 110 additions and 47 deletions
+29 -39
View File
@@ -1,52 +1,42 @@
'use strict';
import utils from './../utils.js';
import platform from '../platform/index.js';
export default platform.hasStandardBrowserEnv ?
// Standard browser envs support document.cookie
(function standardBrowserEnv() {
return {
write: function write(name, value, expires, path, domain, secure) {
const cookie = [];
cookie.push(name + '=' + encodeURIComponent(value));
// Standard browser envs support document.cookie
{
write(name, value, expires, path, domain, secure) {
const cookie = [name + '=' + encodeURIComponent(value)];
if (utils.isNumber(expires)) {
cookie.push('expires=' + new Date(expires).toGMTString());
}
utils.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
if (utils.isString(path)) {
cookie.push('path=' + path);
}
utils.isString(path) && cookie.push('path=' + path);
if (utils.isString(domain)) {
cookie.push('domain=' + domain);
}
utils.isString(domain) && cookie.push('domain=' + domain);
if (secure === true) {
cookie.push('secure');
}
secure === true && cookie.push('secure');
document.cookie = cookie.join('; ');
},
document.cookie = cookie.join('; ');
},
read: function read(name) {
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
},
read(name) {
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
},
remove: function remove(name) {
this.write(name, '', Date.now() - 86400000);
}
};
})() :
remove(name) {
this.write(name, '', Date.now() - 86400000);
}
}
:
// Non-standard browser env (web workers, react-native) lack needed support.
{
write() {},
read() {
return null;
},
remove() {}
};
// Non standard browser env (web workers, react-native) lack needed support.
(function nonStandardBrowserEnv() {
return {
write: function write() {},
read: function read() { return null; },
remove: function remove() {}
};
})();
+1 -1
View File
@@ -13,7 +13,7 @@ export default platform.hasStandardBrowserEnv ?
let originURL;
/**
* Parse a URL to discover it's components
* Parse a URL to discover its components
*
* @param {String} url The URL to be parsed
* @returns {Object}