axios 0.18.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +167 -3
- package/README.md +118 -34
- package/dist/axios.js +696 -566
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -8
- package/dist/axios.min.map +1 -1
- package/index.d.ts +39 -13
- package/lib/adapters/http.js +73 -31
- package/lib/adapters/xhr.js +29 -29
- package/lib/axios.js +2 -1
- package/lib/core/Axios.js +21 -6
- package/lib/core/buildFullPath.js +20 -0
- package/lib/core/dispatchRequest.js +1 -8
- package/lib/core/enhanceError.js +21 -0
- package/lib/core/mergeConfig.js +73 -0
- package/lib/core/settle.js +1 -2
- package/lib/defaults.js +2 -1
- package/lib/helpers/buildURL.js +5 -0
- package/lib/helpers/cookies.js +41 -41
- package/lib/helpers/isURLSameOrigin.js +43 -38
- package/lib/helpers/isValidXss.js +7 -0
- package/lib/utils.js +53 -12
- package/package.json +22 -21
- package/lib/helpers/btoa.js +0 -36
package/lib/defaults.js
CHANGED
@@ -18,7 +18,7 @@ function getDefaultAdapter() {
|
|
18
18
|
if (typeof XMLHttpRequest !== 'undefined') {
|
19
19
|
// For browsers use XHR adapter
|
20
20
|
adapter = require('./adapters/xhr');
|
21
|
-
} else if (typeof process !== 'undefined') {
|
21
|
+
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
22
22
|
// For node use HTTP adapter
|
23
23
|
adapter = require('./adapters/http');
|
24
24
|
}
|
@@ -29,6 +29,7 @@ var defaults = {
|
|
29
29
|
adapter: getDefaultAdapter(),
|
30
30
|
|
31
31
|
transformRequest: [function transformRequest(data, headers) {
|
32
|
+
normalizeHeaderName(headers, 'Accept');
|
32
33
|
normalizeHeaderName(headers, 'Content-Type');
|
33
34
|
if (utils.isFormData(data) ||
|
34
35
|
utils.isArrayBuffer(data) ||
|
package/lib/helpers/buildURL.js
CHANGED
@@ -59,6 +59,11 @@ module.exports = function buildURL(url, params, paramsSerializer) {
|
|
59
59
|
}
|
60
60
|
|
61
61
|
if (serializedParams) {
|
62
|
+
var hashmarkIndex = url.indexOf('#');
|
63
|
+
if (hashmarkIndex !== -1) {
|
64
|
+
url = url.slice(0, hashmarkIndex);
|
65
|
+
}
|
66
|
+
|
62
67
|
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
63
68
|
}
|
64
69
|
|
package/lib/helpers/cookies.js
CHANGED
@@ -6,48 +6,48 @@ module.exports = (
|
|
6
6
|
utils.isStandardBrowserEnv() ?
|
7
7
|
|
8
8
|
// Standard browser envs support document.cookie
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
(function standardBrowserEnv() {
|
10
|
+
return {
|
11
|
+
write: function write(name, value, expires, path, domain, secure) {
|
12
|
+
var cookie = [];
|
13
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
14
|
+
|
15
|
+
if (utils.isNumber(expires)) {
|
16
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
17
|
+
}
|
18
|
+
|
19
|
+
if (utils.isString(path)) {
|
20
|
+
cookie.push('path=' + path);
|
21
|
+
}
|
22
|
+
|
23
|
+
if (utils.isString(domain)) {
|
24
|
+
cookie.push('domain=' + domain);
|
25
|
+
}
|
26
|
+
|
27
|
+
if (secure === true) {
|
28
|
+
cookie.push('secure');
|
29
|
+
}
|
30
|
+
|
31
|
+
document.cookie = cookie.join('; ');
|
32
|
+
},
|
33
|
+
|
34
|
+
read: function read(name) {
|
35
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
36
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
37
|
+
},
|
38
|
+
|
39
|
+
remove: function remove(name) {
|
40
|
+
this.write(name, '', Date.now() - 86400000);
|
17
41
|
}
|
18
|
-
|
19
|
-
|
20
|
-
cookie.push('path=' + path);
|
21
|
-
}
|
22
|
-
|
23
|
-
if (utils.isString(domain)) {
|
24
|
-
cookie.push('domain=' + domain);
|
25
|
-
}
|
26
|
-
|
27
|
-
if (secure === true) {
|
28
|
-
cookie.push('secure');
|
29
|
-
}
|
30
|
-
|
31
|
-
document.cookie = cookie.join('; ');
|
32
|
-
},
|
33
|
-
|
34
|
-
read: function read(name) {
|
35
|
-
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
36
|
-
return (match ? decodeURIComponent(match[3]) : null);
|
37
|
-
},
|
38
|
-
|
39
|
-
remove: function remove(name) {
|
40
|
-
this.write(name, '', Date.now() - 86400000);
|
41
|
-
}
|
42
|
-
};
|
43
|
-
})() :
|
42
|
+
};
|
43
|
+
})() :
|
44
44
|
|
45
45
|
// Non standard browser env (web workers, react-native) lack needed support.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
(function nonStandardBrowserEnv() {
|
47
|
+
return {
|
48
|
+
write: function write() {},
|
49
|
+
read: function read() { return null; },
|
50
|
+
remove: function remove() {}
|
51
|
+
};
|
52
|
+
})()
|
53
53
|
);
|
@@ -1,68 +1,73 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var utils = require('./../utils');
|
4
|
+
var isValidXss = require('./isValidXss');
|
4
5
|
|
5
6
|
module.exports = (
|
6
7
|
utils.isStandardBrowserEnv() ?
|
7
8
|
|
8
9
|
// Standard browser envs have full support of the APIs needed to test
|
9
10
|
// whether the request URL is of the same origin as current location.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
(function standardBrowserEnv() {
|
12
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
13
|
+
var urlParsingNode = document.createElement('a');
|
14
|
+
var originURL;
|
14
15
|
|
15
|
-
|
16
|
+
/**
|
16
17
|
* Parse a URL to discover it's components
|
17
18
|
*
|
18
19
|
* @param {String} url The URL to be parsed
|
19
20
|
* @returns {Object}
|
20
21
|
*/
|
21
|
-
|
22
|
-
|
22
|
+
function resolveURL(url) {
|
23
|
+
var href = url;
|
23
24
|
|
24
|
-
|
25
|
+
if (isValidXss(url)) {
|
26
|
+
throw new Error('URL contains XSS injection attempt');
|
27
|
+
}
|
28
|
+
|
29
|
+
if (msie) {
|
25
30
|
// IE needs attribute set twice to normalize properties
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
urlParsingNode.setAttribute('href', href);
|
32
|
+
href = urlParsingNode.href;
|
33
|
+
}
|
29
34
|
|
30
|
-
|
35
|
+
urlParsingNode.setAttribute('href', href);
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
37
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
38
|
+
return {
|
39
|
+
href: urlParsingNode.href,
|
40
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
41
|
+
host: urlParsingNode.host,
|
42
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
43
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
44
|
+
hostname: urlParsingNode.hostname,
|
45
|
+
port: urlParsingNode.port,
|
46
|
+
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
47
|
+
urlParsingNode.pathname :
|
48
|
+
'/' + urlParsingNode.pathname
|
49
|
+
};
|
50
|
+
}
|
46
51
|
|
47
|
-
|
52
|
+
originURL = resolveURL(window.location.href);
|
48
53
|
|
49
|
-
|
54
|
+
/**
|
50
55
|
* Determine if a URL shares the same origin as the current location
|
51
56
|
*
|
52
57
|
* @param {String} requestURL The URL to test
|
53
58
|
* @returns {boolean} True if URL shares the same origin, otherwise false
|
54
59
|
*/
|
55
|
-
|
56
|
-
|
57
|
-
|
60
|
+
return function isURLSameOrigin(requestURL) {
|
61
|
+
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
62
|
+
return (parsed.protocol === originURL.protocol &&
|
58
63
|
parsed.host === originURL.host);
|
59
|
-
|
60
|
-
|
64
|
+
};
|
65
|
+
})() :
|
61
66
|
|
62
67
|
// Non standard browser envs (web workers, react-native) lack needed support.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
+
(function nonStandardBrowserEnv() {
|
69
|
+
return function isURLSameOrigin() {
|
70
|
+
return true;
|
71
|
+
};
|
72
|
+
})()
|
68
73
|
);
|
package/lib/utils.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var bind = require('./helpers/bind');
|
4
|
-
var isBuffer = require('is-buffer');
|
5
4
|
|
6
5
|
/*global toString:true*/
|
7
6
|
|
@@ -19,6 +18,27 @@ function isArray(val) {
|
|
19
18
|
return toString.call(val) === '[object Array]';
|
20
19
|
}
|
21
20
|
|
21
|
+
/**
|
22
|
+
* Determine if a value is undefined
|
23
|
+
*
|
24
|
+
* @param {Object} val The value to test
|
25
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
26
|
+
*/
|
27
|
+
function isUndefined(val) {
|
28
|
+
return typeof val === 'undefined';
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Determine if a value is a Buffer
|
33
|
+
*
|
34
|
+
* @param {Object} val The value to test
|
35
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
36
|
+
*/
|
37
|
+
function isBuffer(val) {
|
38
|
+
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
39
|
+
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
40
|
+
}
|
41
|
+
|
22
42
|
/**
|
23
43
|
* Determine if a value is an ArrayBuffer
|
24
44
|
*
|
@@ -75,16 +95,6 @@ function isNumber(val) {
|
|
75
95
|
return typeof val === 'number';
|
76
96
|
}
|
77
97
|
|
78
|
-
/**
|
79
|
-
* Determine if a value is undefined
|
80
|
-
*
|
81
|
-
* @param {Object} val The value to test
|
82
|
-
* @returns {boolean} True if the value is undefined, otherwise false
|
83
|
-
*/
|
84
|
-
function isUndefined(val) {
|
85
|
-
return typeof val === 'undefined';
|
86
|
-
}
|
87
|
-
|
88
98
|
/**
|
89
99
|
* Determine if a value is an Object
|
90
100
|
*
|
@@ -177,9 +187,13 @@ function trim(str) {
|
|
177
187
|
*
|
178
188
|
* react-native:
|
179
189
|
* navigator.product -> 'ReactNative'
|
190
|
+
* nativescript
|
191
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
180
192
|
*/
|
181
193
|
function isStandardBrowserEnv() {
|
182
|
-
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative'
|
194
|
+
if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
|
195
|
+
navigator.product === 'NativeScript' ||
|
196
|
+
navigator.product === 'NS')) {
|
183
197
|
return false;
|
184
198
|
}
|
185
199
|
return (
|
@@ -260,6 +274,32 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
260
274
|
return result;
|
261
275
|
}
|
262
276
|
|
277
|
+
/**
|
278
|
+
* Function equal to merge with the difference being that no reference
|
279
|
+
* to original objects is kept.
|
280
|
+
*
|
281
|
+
* @see merge
|
282
|
+
* @param {Object} obj1 Object to merge
|
283
|
+
* @returns {Object} Result of all merge properties
|
284
|
+
*/
|
285
|
+
function deepMerge(/* obj1, obj2, obj3, ... */) {
|
286
|
+
var result = {};
|
287
|
+
function assignValue(val, key) {
|
288
|
+
if (typeof result[key] === 'object' && typeof val === 'object') {
|
289
|
+
result[key] = deepMerge(result[key], val);
|
290
|
+
} else if (typeof val === 'object') {
|
291
|
+
result[key] = deepMerge({}, val);
|
292
|
+
} else {
|
293
|
+
result[key] = val;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
298
|
+
forEach(arguments[i], assignValue);
|
299
|
+
}
|
300
|
+
return result;
|
301
|
+
}
|
302
|
+
|
263
303
|
/**
|
264
304
|
* Extends object a by mutably adding to it the properties of object b.
|
265
305
|
*
|
@@ -298,6 +338,7 @@ module.exports = {
|
|
298
338
|
isStandardBrowserEnv: isStandardBrowserEnv,
|
299
339
|
forEach: forEach,
|
300
340
|
merge: merge,
|
341
|
+
deepMerge: deepMerge,
|
301
342
|
extend: extend,
|
302
343
|
trim: trim
|
303
344
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.19.1",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -11,7 +11,8 @@
|
|
11
11
|
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",
|
12
12
|
"postversion": "git push && git push --tags",
|
13
13
|
"examples": "node ./examples/server.js",
|
14
|
-
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
|
14
|
+
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
15
|
+
"fix": "eslint --fix lib/**/*.js"
|
15
16
|
},
|
16
17
|
"repository": {
|
17
18
|
"type": "git",
|
@@ -31,48 +32,48 @@
|
|
31
32
|
},
|
32
33
|
"homepage": "https://github.com/axios/axios",
|
33
34
|
"devDependencies": {
|
34
|
-
"bundlesize": "^0.
|
35
|
-
"coveralls": "^
|
36
|
-
"es6-promise": "^4.
|
37
|
-
"grunt": "^1.0.
|
35
|
+
"bundlesize": "^0.17.0",
|
36
|
+
"coveralls": "^3.0.0",
|
37
|
+
"es6-promise": "^4.2.4",
|
38
|
+
"grunt": "^1.0.2",
|
38
39
|
"grunt-banner": "^0.6.0",
|
39
40
|
"grunt-cli": "^1.2.0",
|
40
|
-
"grunt-contrib-clean": "^1.
|
41
|
-
"grunt-contrib-nodeunit": "^1.0.0",
|
41
|
+
"grunt-contrib-clean": "^1.1.0",
|
42
42
|
"grunt-contrib-watch": "^1.0.0",
|
43
|
-
"grunt-eslint": "^
|
43
|
+
"grunt-eslint": "^20.1.0",
|
44
44
|
"grunt-karma": "^2.0.0",
|
45
|
-
"grunt-
|
45
|
+
"grunt-mocha-test": "^0.13.3",
|
46
|
+
"grunt-ts": "^6.0.0-beta.19",
|
46
47
|
"grunt-webpack": "^1.0.18",
|
47
48
|
"istanbul-instrumenter-loader": "^1.0.0",
|
48
49
|
"jasmine-core": "^2.4.1",
|
49
50
|
"karma": "^1.3.0",
|
50
|
-
"karma-chrome-launcher": "^2.
|
51
|
-
"karma-coverage": "^1.
|
52
|
-
"karma-firefox-launcher": "^1.
|
53
|
-
"karma-jasmine": "^1.
|
51
|
+
"karma-chrome-launcher": "^2.2.0",
|
52
|
+
"karma-coverage": "^1.1.1",
|
53
|
+
"karma-firefox-launcher": "^1.1.0",
|
54
|
+
"karma-jasmine": "^1.1.1",
|
54
55
|
"karma-jasmine-ajax": "^0.1.13",
|
55
56
|
"karma-opera-launcher": "^1.0.0",
|
56
57
|
"karma-safari-launcher": "^1.0.0",
|
57
|
-
"karma-sauce-launcher": "^1.
|
58
|
+
"karma-sauce-launcher": "^1.2.0",
|
58
59
|
"karma-sinon": "^1.0.5",
|
59
60
|
"karma-sourcemap-loader": "^0.3.7",
|
60
61
|
"karma-webpack": "^1.7.0",
|
61
62
|
"load-grunt-tasks": "^3.5.2",
|
62
63
|
"minimist": "^1.2.0",
|
63
|
-
"
|
64
|
+
"mocha": "^5.2.0",
|
65
|
+
"sinon": "^4.5.0",
|
66
|
+
"typescript": "^2.8.1",
|
67
|
+
"url-search-params": "^0.10.0",
|
64
68
|
"webpack": "^1.13.1",
|
65
|
-
"webpack-dev-server": "^1.14.1"
|
66
|
-
"url-search-params": "^0.6.1",
|
67
|
-
"typescript": "^2.0.3"
|
69
|
+
"webpack-dev-server": "^1.14.1"
|
68
70
|
},
|
69
71
|
"browser": {
|
70
72
|
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
|
71
73
|
},
|
72
74
|
"typings": "./index.d.ts",
|
73
75
|
"dependencies": {
|
74
|
-
"follow-redirects": "
|
75
|
-
"is-buffer": "^1.1.5"
|
76
|
+
"follow-redirects": "1.5.10"
|
76
77
|
},
|
77
78
|
"bundlesize": [
|
78
79
|
{
|
package/lib/helpers/btoa.js
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
// btoa polyfill for IE<10 courtesy https://github.com/davidchambers/Base64.js
|
4
|
-
|
5
|
-
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
6
|
-
|
7
|
-
function E() {
|
8
|
-
this.message = 'String contains an invalid character';
|
9
|
-
}
|
10
|
-
E.prototype = new Error;
|
11
|
-
E.prototype.code = 5;
|
12
|
-
E.prototype.name = 'InvalidCharacterError';
|
13
|
-
|
14
|
-
function btoa(input) {
|
15
|
-
var str = String(input);
|
16
|
-
var output = '';
|
17
|
-
for (
|
18
|
-
// initialize result and counter
|
19
|
-
var block, charCode, idx = 0, map = chars;
|
20
|
-
// if the next str index does not exist:
|
21
|
-
// change the mapping table to "="
|
22
|
-
// check if d has no fractional digits
|
23
|
-
str.charAt(idx | 0) || (map = '=', idx % 1);
|
24
|
-
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
|
25
|
-
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
26
|
-
) {
|
27
|
-
charCode = str.charCodeAt(idx += 3 / 4);
|
28
|
-
if (charCode > 0xFF) {
|
29
|
-
throw new E();
|
30
|
-
}
|
31
|
-
block = block << 8 | charCode;
|
32
|
-
}
|
33
|
-
return output;
|
34
|
-
}
|
35
|
-
|
36
|
-
module.exports = btoa;
|