axios 0.19.1 → 0.21.0
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 +296 -43
- package/README.md +108 -19
- package/UPGRADE_GUIDE.md +1 -1
- package/dist/axios.js +170 -167
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -2
- package/dist/axios.min.map +1 -1
- package/index.d.ts +10 -7
- package/lib/adapters/http.js +23 -15
- package/lib/adapters/xhr.js +3 -4
- package/lib/core/Axios.js +4 -3
- package/lib/core/enhanceError.js +1 -1
- package/lib/core/mergeConfig.js +46 -32
- package/lib/core/settle.js +1 -1
- package/lib/defaults.js +1 -0
- package/lib/helpers/buildURL.js +0 -1
- package/lib/helpers/isURLSameOrigin.js +0 -5
- package/lib/utils.js +36 -29
- package/package.json +4 -2
- package/lib/helpers/isValidXss.js +0 -7
package/index.d.ts
CHANGED
@@ -29,15 +29,16 @@ export type Method =
|
|
29
29
|
| 'post' | 'POST'
|
30
30
|
| 'put' | 'PUT'
|
31
31
|
| 'patch' | 'PATCH'
|
32
|
+
| 'purge' | 'PURGE'
|
32
33
|
| 'link' | 'LINK'
|
33
34
|
| 'unlink' | 'UNLINK'
|
34
35
|
|
35
|
-
export type ResponseType =
|
36
|
-
| 'arraybuffer'
|
37
|
-
| 'blob'
|
38
|
-
| 'document'
|
39
|
-
| 'json'
|
40
|
-
| 'text'
|
36
|
+
export type ResponseType =
|
37
|
+
| 'arraybuffer'
|
38
|
+
| 'blob'
|
39
|
+
| 'document'
|
40
|
+
| 'json'
|
41
|
+
| 'text'
|
41
42
|
| 'stream'
|
42
43
|
|
43
44
|
export interface AxiosRequestConfig {
|
@@ -61,13 +62,15 @@ export interface AxiosRequestConfig {
|
|
61
62
|
onUploadProgress?: (progressEvent: any) => void;
|
62
63
|
onDownloadProgress?: (progressEvent: any) => void;
|
63
64
|
maxContentLength?: number;
|
64
|
-
validateStatus?: (status: number) => boolean;
|
65
|
+
validateStatus?: ((status: number) => boolean) | null;
|
66
|
+
maxBodyLength?: number;
|
65
67
|
maxRedirects?: number;
|
66
68
|
socketPath?: string | null;
|
67
69
|
httpAgent?: any;
|
68
70
|
httpsAgent?: any;
|
69
71
|
proxy?: AxiosProxyConfig | false;
|
70
72
|
cancelToken?: CancelToken;
|
73
|
+
decompress?: boolean;
|
71
74
|
}
|
72
75
|
|
73
76
|
export interface AxiosResponse<T = any> {
|
package/lib/adapters/http.js
CHANGED
@@ -171,8 +171,8 @@ module.exports = function httpAdapter(config) {
|
|
171
171
|
transport = isHttpsProxy ? httpsFollow : httpFollow;
|
172
172
|
}
|
173
173
|
|
174
|
-
if (config.
|
175
|
-
options.maxBodyLength = config.
|
174
|
+
if (config.maxBodyLength > -1) {
|
175
|
+
options.maxBodyLength = config.maxBodyLength;
|
176
176
|
}
|
177
177
|
|
178
178
|
// Create the request
|
@@ -181,22 +181,27 @@ module.exports = function httpAdapter(config) {
|
|
181
181
|
|
182
182
|
// uncompress the response body transparently if required
|
183
183
|
var stream = res;
|
184
|
-
switch (res.headers['content-encoding']) {
|
185
|
-
/*eslint default-case:0*/
|
186
|
-
case 'gzip':
|
187
|
-
case 'compress':
|
188
|
-
case 'deflate':
|
189
|
-
// add the unzipper to the body stream processing pipeline
|
190
|
-
stream = (res.statusCode === 204) ? stream : stream.pipe(zlib.createUnzip());
|
191
|
-
|
192
|
-
// remove the content-encoding in order to not confuse downstream operations
|
193
|
-
delete res.headers['content-encoding'];
|
194
|
-
break;
|
195
|
-
}
|
196
184
|
|
197
185
|
// return the last request in case of redirects
|
198
186
|
var lastRequest = res.req || req;
|
199
187
|
|
188
|
+
|
189
|
+
// if no content, is HEAD request or decompress disabled we should not decompress
|
190
|
+
if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) {
|
191
|
+
switch (res.headers['content-encoding']) {
|
192
|
+
/*eslint default-case:0*/
|
193
|
+
case 'gzip':
|
194
|
+
case 'compress':
|
195
|
+
case 'deflate':
|
196
|
+
// add the unzipper to the body stream processing pipeline
|
197
|
+
stream = stream.pipe(zlib.createUnzip());
|
198
|
+
|
199
|
+
// remove the content-encoding in order to not confuse downstream operations
|
200
|
+
delete res.headers['content-encoding'];
|
201
|
+
break;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
200
205
|
var response = {
|
201
206
|
status: res.statusCode,
|
202
207
|
statusText: res.statusMessage,
|
@@ -230,6 +235,9 @@ module.exports = function httpAdapter(config) {
|
|
230
235
|
var responseData = Buffer.concat(responseBuffer);
|
231
236
|
if (config.responseType !== 'arraybuffer') {
|
232
237
|
responseData = responseData.toString(config.responseEncoding);
|
238
|
+
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
|
239
|
+
responseData = utils.stripBOM(responseData);
|
240
|
+
}
|
233
241
|
}
|
234
242
|
|
235
243
|
response.data = responseData;
|
@@ -240,7 +248,7 @@ module.exports = function httpAdapter(config) {
|
|
240
248
|
|
241
249
|
// Handle errors
|
242
250
|
req.on('error', function handleRequestError(err) {
|
243
|
-
if (req.aborted) return;
|
251
|
+
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
|
244
252
|
reject(enhanceError(err, config, null, req));
|
245
253
|
});
|
246
254
|
|
package/lib/adapters/xhr.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
var utils = require('./../utils');
|
4
4
|
var settle = require('./../core/settle');
|
5
|
+
var cookies = require('./../helpers/cookies');
|
5
6
|
var buildURL = require('./../helpers/buildURL');
|
6
7
|
var buildFullPath = require('../core/buildFullPath');
|
7
8
|
var parseHeaders = require('./../helpers/parseHeaders');
|
@@ -22,7 +23,7 @@ module.exports = function xhrAdapter(config) {
|
|
22
23
|
// HTTP basic authentication
|
23
24
|
if (config.auth) {
|
24
25
|
var username = config.auth.username || '';
|
25
|
-
var password = config.auth.password
|
26
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
26
27
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
27
28
|
}
|
28
29
|
|
@@ -103,8 +104,6 @@ module.exports = function xhrAdapter(config) {
|
|
103
104
|
// This is only done if running in a standard browser environment.
|
104
105
|
// Specifically not if we're in a web worker, or react-native.
|
105
106
|
if (utils.isStandardBrowserEnv()) {
|
106
|
-
var cookies = require('./../helpers/cookies');
|
107
|
-
|
108
107
|
// Add xsrf header
|
109
108
|
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
110
109
|
cookies.read(config.xsrfCookieName) :
|
@@ -170,7 +169,7 @@ module.exports = function xhrAdapter(config) {
|
|
170
169
|
});
|
171
170
|
}
|
172
171
|
|
173
|
-
if (requestData
|
172
|
+
if (!requestData) {
|
174
173
|
requestData = null;
|
175
174
|
}
|
176
175
|
|
package/lib/core/Axios.js
CHANGED
@@ -73,9 +73,10 @@ Axios.prototype.getUri = function getUri(config) {
|
|
73
73
|
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
74
74
|
/*eslint func-names:0*/
|
75
75
|
Axios.prototype[method] = function(url, config) {
|
76
|
-
return this.request(
|
76
|
+
return this.request(mergeConfig(config || {}, {
|
77
77
|
method: method,
|
78
|
-
url: url
|
78
|
+
url: url,
|
79
|
+
data: (config || {}).data
|
79
80
|
}));
|
80
81
|
};
|
81
82
|
});
|
@@ -83,7 +84,7 @@ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData
|
|
83
84
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
84
85
|
/*eslint func-names:0*/
|
85
86
|
Axios.prototype[method] = function(url, data, config) {
|
86
|
-
return this.request(
|
87
|
+
return this.request(mergeConfig(config || {}, {
|
87
88
|
method: method,
|
88
89
|
url: url,
|
89
90
|
data: data
|
package/lib/core/enhanceError.js
CHANGED
@@ -20,7 +20,7 @@ module.exports = function enhanceError(error, config, code, request, response) {
|
|
20
20
|
error.response = response;
|
21
21
|
error.isAxiosError = true;
|
22
22
|
|
23
|
-
error.toJSON = function() {
|
23
|
+
error.toJSON = function toJSON() {
|
24
24
|
return {
|
25
25
|
// Standard
|
26
26
|
message: this.message,
|
package/lib/core/mergeConfig.js
CHANGED
@@ -15,59 +15,73 @@ module.exports = function mergeConfig(config1, config2) {
|
|
15
15
|
config2 = config2 || {};
|
16
16
|
var config = {};
|
17
17
|
|
18
|
-
var valueFromConfig2Keys = ['url', 'method', '
|
19
|
-
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy'];
|
18
|
+
var valueFromConfig2Keys = ['url', 'method', 'data'];
|
19
|
+
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
|
20
20
|
var defaultToConfig2Keys = [
|
21
|
-
'baseURL', '
|
22
|
-
'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
|
23
|
-
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress',
|
24
|
-
'maxContentLength', '
|
25
|
-
'httpsAgent', 'cancelToken', 'socketPath'
|
21
|
+
'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
|
22
|
+
'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
|
23
|
+
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
|
24
|
+
'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
|
25
|
+
'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
|
26
26
|
];
|
27
|
+
var directMergeKeys = ['validateStatus'];
|
28
|
+
|
29
|
+
function getMergedValue(target, source) {
|
30
|
+
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
31
|
+
return utils.merge(target, source);
|
32
|
+
} else if (utils.isPlainObject(source)) {
|
33
|
+
return utils.merge({}, source);
|
34
|
+
} else if (utils.isArray(source)) {
|
35
|
+
return source.slice();
|
36
|
+
}
|
37
|
+
return source;
|
38
|
+
}
|
39
|
+
|
40
|
+
function mergeDeepProperties(prop) {
|
41
|
+
if (!utils.isUndefined(config2[prop])) {
|
42
|
+
config[prop] = getMergedValue(config1[prop], config2[prop]);
|
43
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
44
|
+
config[prop] = getMergedValue(undefined, config1[prop]);
|
45
|
+
}
|
46
|
+
}
|
27
47
|
|
28
48
|
utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
|
29
|
-
if (
|
30
|
-
config[prop] = config2[prop];
|
49
|
+
if (!utils.isUndefined(config2[prop])) {
|
50
|
+
config[prop] = getMergedValue(undefined, config2[prop]);
|
31
51
|
}
|
32
52
|
});
|
33
53
|
|
34
|
-
utils.forEach(mergeDeepPropertiesKeys,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
config[prop] = config2[prop];
|
39
|
-
} else if (utils.
|
40
|
-
config[prop] =
|
41
|
-
} else if (typeof config1[prop] !== 'undefined') {
|
42
|
-
config[prop] = config1[prop];
|
54
|
+
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
|
55
|
+
|
56
|
+
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
|
57
|
+
if (!utils.isUndefined(config2[prop])) {
|
58
|
+
config[prop] = getMergedValue(undefined, config2[prop]);
|
59
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
60
|
+
config[prop] = getMergedValue(undefined, config1[prop]);
|
43
61
|
}
|
44
62
|
});
|
45
63
|
|
46
|
-
utils.forEach(
|
47
|
-
if (
|
48
|
-
config[prop] = config2[prop];
|
49
|
-
} else if (
|
50
|
-
config[prop] = config1[prop];
|
64
|
+
utils.forEach(directMergeKeys, function merge(prop) {
|
65
|
+
if (prop in config2) {
|
66
|
+
config[prop] = getMergedValue(config1[prop], config2[prop]);
|
67
|
+
} else if (prop in config1) {
|
68
|
+
config[prop] = getMergedValue(undefined, config1[prop]);
|
51
69
|
}
|
52
70
|
});
|
53
71
|
|
54
72
|
var axiosKeys = valueFromConfig2Keys
|
55
73
|
.concat(mergeDeepPropertiesKeys)
|
56
|
-
.concat(defaultToConfig2Keys)
|
74
|
+
.concat(defaultToConfig2Keys)
|
75
|
+
.concat(directMergeKeys);
|
57
76
|
|
58
77
|
var otherKeys = Object
|
59
|
-
.keys(
|
78
|
+
.keys(config1)
|
79
|
+
.concat(Object.keys(config2))
|
60
80
|
.filter(function filterAxiosKeys(key) {
|
61
81
|
return axiosKeys.indexOf(key) === -1;
|
62
82
|
});
|
63
83
|
|
64
|
-
utils.forEach(otherKeys,
|
65
|
-
if (typeof config2[prop] !== 'undefined') {
|
66
|
-
config[prop] = config2[prop];
|
67
|
-
} else if (typeof config1[prop] !== 'undefined') {
|
68
|
-
config[prop] = config1[prop];
|
69
|
-
}
|
70
|
-
});
|
84
|
+
utils.forEach(otherKeys, mergeDeepProperties);
|
71
85
|
|
72
86
|
return config;
|
73
87
|
};
|
package/lib/core/settle.js
CHANGED
@@ -11,7 +11,7 @@ var createError = require('./createError');
|
|
11
11
|
*/
|
12
12
|
module.exports = function settle(resolve, reject, response) {
|
13
13
|
var validateStatus = response.config.validateStatus;
|
14
|
-
if (!validateStatus || validateStatus(response.status)) {
|
14
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
15
15
|
resolve(response);
|
16
16
|
} else {
|
17
17
|
reject(createError(
|
package/lib/defaults.js
CHANGED
package/lib/helpers/buildURL.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var utils = require('./../utils');
|
4
|
-
var isValidXss = require('./isValidXss');
|
5
4
|
|
6
5
|
module.exports = (
|
7
6
|
utils.isStandardBrowserEnv() ?
|
@@ -22,10 +21,6 @@ module.exports = (
|
|
22
21
|
function resolveURL(url) {
|
23
22
|
var href = url;
|
24
23
|
|
25
|
-
if (isValidXss(url)) {
|
26
|
-
throw new Error('URL contains XSS injection attempt');
|
27
|
-
}
|
28
|
-
|
29
24
|
if (msie) {
|
30
25
|
// IE needs attribute set twice to normalize properties
|
31
26
|
urlParsingNode.setAttribute('href', href);
|
package/lib/utils.js
CHANGED
@@ -105,6 +105,21 @@ function isObject(val) {
|
|
105
105
|
return val !== null && typeof val === 'object';
|
106
106
|
}
|
107
107
|
|
108
|
+
/**
|
109
|
+
* Determine if a value is a plain Object
|
110
|
+
*
|
111
|
+
* @param {Object} val The value to test
|
112
|
+
* @return {boolean} True if value is a plain Object, otherwise false
|
113
|
+
*/
|
114
|
+
function isPlainObject(val) {
|
115
|
+
if (toString.call(val) !== '[object Object]') {
|
116
|
+
return false;
|
117
|
+
}
|
118
|
+
|
119
|
+
var prototype = Object.getPrototypeOf(val);
|
120
|
+
return prototype === null || prototype === Object.prototype;
|
121
|
+
}
|
122
|
+
|
108
123
|
/**
|
109
124
|
* Determine if a value is a Date
|
110
125
|
*
|
@@ -261,34 +276,12 @@ function forEach(obj, fn) {
|
|
261
276
|
function merge(/* obj1, obj2, obj3, ... */) {
|
262
277
|
var result = {};
|
263
278
|
function assignValue(val, key) {
|
264
|
-
if (
|
279
|
+
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
265
280
|
result[key] = merge(result[key], val);
|
266
|
-
} else {
|
267
|
-
result[key] = val;
|
268
|
-
}
|
269
|
-
|
270
|
-
|
271
|
-
for (var i = 0, l = arguments.length; i < l; i++) {
|
272
|
-
forEach(arguments[i], assignValue);
|
273
|
-
}
|
274
|
-
return result;
|
275
|
-
}
|
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);
|
281
|
+
} else if (isPlainObject(val)) {
|
282
|
+
result[key] = merge({}, val);
|
283
|
+
} else if (isArray(val)) {
|
284
|
+
result[key] = val.slice();
|
292
285
|
} else {
|
293
286
|
result[key] = val;
|
294
287
|
}
|
@@ -319,6 +312,19 @@ function extend(a, b, thisArg) {
|
|
319
312
|
return a;
|
320
313
|
}
|
321
314
|
|
315
|
+
/**
|
316
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
317
|
+
*
|
318
|
+
* @param {string} content with BOM
|
319
|
+
* @return {string} content value without BOM
|
320
|
+
*/
|
321
|
+
function stripBOM(content) {
|
322
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
323
|
+
content = content.slice(1);
|
324
|
+
}
|
325
|
+
return content;
|
326
|
+
}
|
327
|
+
|
322
328
|
module.exports = {
|
323
329
|
isArray: isArray,
|
324
330
|
isArrayBuffer: isArrayBuffer,
|
@@ -328,6 +334,7 @@ module.exports = {
|
|
328
334
|
isString: isString,
|
329
335
|
isNumber: isNumber,
|
330
336
|
isObject: isObject,
|
337
|
+
isPlainObject: isPlainObject,
|
331
338
|
isUndefined: isUndefined,
|
332
339
|
isDate: isDate,
|
333
340
|
isFile: isFile,
|
@@ -338,7 +345,7 @@ module.exports = {
|
|
338
345
|
isStandardBrowserEnv: isStandardBrowserEnv,
|
339
346
|
forEach: forEach,
|
340
347
|
merge: merge,
|
341
|
-
deepMerge: deepMerge,
|
342
348
|
extend: extend,
|
343
|
-
trim: trim
|
349
|
+
trim: trim,
|
350
|
+
stripBOM: stripBOM
|
344
351
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.21.0",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -71,9 +71,11 @@
|
|
71
71
|
"browser": {
|
72
72
|
"./lib/adapters/http.js": "./lib/adapters/xhr.js"
|
73
73
|
},
|
74
|
+
"jsdelivr": "dist/axios.min.js",
|
75
|
+
"unpkg": "dist/axios.min.js",
|
74
76
|
"typings": "./index.d.ts",
|
75
77
|
"dependencies": {
|
76
|
-
"follow-redirects": "1.
|
78
|
+
"follow-redirects": "^1.10.0"
|
77
79
|
},
|
78
80
|
"bundlesize": [
|
79
81
|
{
|