forked from axios/axios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(withXSRFToken): added withXSRFToken option as a workaround to ac…
…hieve the old `withCredentials` behavior; (axios#6046)
- Loading branch information
1 parent
7009715
commit cff9967
Showing
8 changed files
with
118 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
|
||
if (utils.isNumber(expires)) { | ||
cookie.push('expires=' + new Date(expires).toGMTString()); | ||
} | ||
|
||
if (utils.isString(path)) { | ||
cookie.push('path=' + path); | ||
} | ||
|
||
if (utils.isString(domain)) { | ||
cookie.push('domain=' + domain); | ||
} | ||
|
||
if (secure === true) { | ||
cookie.push('secure'); | ||
} | ||
|
||
document.cookie = cookie.join('; '); | ||
}, | ||
|
||
read: function 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); | ||
} | ||
}; | ||
})() : | ||
|
||
// 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() {} | ||
}; | ||
})(); | ||
// Standard browser envs support document.cookie | ||
{ | ||
write(name, value, expires, path, domain, secure) { | ||
const cookie = [name + '=' + encodeURIComponent(value)]; | ||
|
||
utils.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString()); | ||
|
||
utils.isString(path) && cookie.push('path=' + path); | ||
|
||
utils.isString(domain) && cookie.push('domain=' + domain); | ||
|
||
secure === true && cookie.push('secure'); | ||
|
||
document.cookie = cookie.join('; '); | ||
}, | ||
|
||
read(name) { | ||
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)')); | ||
return (match ? decodeURIComponent(match[3]) : null); | ||
}, | ||
|
||
remove(name) { | ||
this.write(name, '', Date.now() - 86400000); | ||
} | ||
} | ||
|
||
: | ||
|
||
// Non-standard browser env (web workers, react-native) lack needed support. | ||
{ | ||
write() {}, | ||
read() { | ||
return null; | ||
}, | ||
remove() {} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters