axios 0.19.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 +65 -4
- package/README.md +31 -6
- package/dist/axios.js +204 -139
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -8
- package/dist/axios.min.map +1 -1
- package/index.d.ts +5 -0
- package/lib/adapters/http.js +12 -8
- package/lib/adapters/xhr.js +11 -5
- package/lib/core/Axios.js +9 -1
- package/lib/core/buildFullPath.js +20 -0
- package/lib/core/dispatchRequest.js +1 -8
- package/lib/core/mergeConfig.js +31 -9
- package/lib/defaults.js +4 -5
- package/lib/helpers/isURLSameOrigin.js +5 -0
- package/lib/helpers/isValidXss.js +7 -0
- package/lib/utils.js +21 -11
- package/package.json +2 -3
package/index.d.ts
CHANGED
@@ -29,6 +29,8 @@ export type Method =
|
|
29
29
|
| 'post' | 'POST'
|
30
30
|
| 'put' | 'PUT'
|
31
31
|
| 'patch' | 'PATCH'
|
32
|
+
| 'link' | 'LINK'
|
33
|
+
| 'unlink' | 'UNLINK'
|
32
34
|
|
33
35
|
export type ResponseType =
|
34
36
|
| 'arraybuffer'
|
@@ -49,6 +51,7 @@ export interface AxiosRequestConfig {
|
|
49
51
|
paramsSerializer?: (params: any) => string;
|
50
52
|
data?: any;
|
51
53
|
timeout?: number;
|
54
|
+
timeoutErrorMessage?: string;
|
52
55
|
withCredentials?: boolean;
|
53
56
|
adapter?: AxiosAdapter;
|
54
57
|
auth?: AxiosBasicCredentials;
|
@@ -82,6 +85,7 @@ export interface AxiosError<T = any> extends Error {
|
|
82
85
|
request?: any;
|
83
86
|
response?: AxiosResponse<T>;
|
84
87
|
isAxiosError: boolean;
|
88
|
+
toJSON: () => object;
|
85
89
|
}
|
86
90
|
|
87
91
|
export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
|
@@ -133,6 +137,7 @@ export interface AxiosInstance {
|
|
133
137
|
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
134
138
|
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
135
139
|
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
140
|
+
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
136
141
|
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
137
142
|
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
138
143
|
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
package/lib/adapters/http.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
var utils = require('./../utils');
|
4
4
|
var settle = require('./../core/settle');
|
5
|
+
var buildFullPath = require('../core/buildFullPath');
|
5
6
|
var buildURL = require('./../helpers/buildURL');
|
6
7
|
var http = require('http');
|
7
8
|
var https = require('https');
|
@@ -18,13 +19,10 @@ var isHttps = /https:?/;
|
|
18
19
|
/*eslint consistent-return:0*/
|
19
20
|
module.exports = function httpAdapter(config) {
|
20
21
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
21
|
-
var timer;
|
22
22
|
var resolve = function resolve(value) {
|
23
|
-
clearTimeout(timer);
|
24
23
|
resolvePromise(value);
|
25
24
|
};
|
26
25
|
var reject = function reject(value) {
|
27
|
-
clearTimeout(timer);
|
28
26
|
rejectPromise(value);
|
29
27
|
};
|
30
28
|
var data = config.data;
|
@@ -64,7 +62,8 @@ module.exports = function httpAdapter(config) {
|
|
64
62
|
}
|
65
63
|
|
66
64
|
// Parse url
|
67
|
-
var
|
65
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
66
|
+
var parsed = url.parse(fullPath);
|
68
67
|
var protocol = parsed.protocol || 'http:';
|
69
68
|
|
70
69
|
if (!auth && parsed.auth) {
|
@@ -86,6 +85,7 @@ module.exports = function httpAdapter(config) {
|
|
86
85
|
method: config.method.toUpperCase(),
|
87
86
|
headers: headers,
|
88
87
|
agent: agent,
|
88
|
+
agents: { http: config.httpAgent, https: config.httpsAgent },
|
89
89
|
auth: auth
|
90
90
|
};
|
91
91
|
|
@@ -118,8 +118,7 @@ module.exports = function httpAdapter(config) {
|
|
118
118
|
return true;
|
119
119
|
}
|
120
120
|
if (proxyElement[0] === '.' &&
|
121
|
-
parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement
|
122
|
-
proxyElement.match(/\./g).length === parsed.hostname.match(/\./g).length) {
|
121
|
+
parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement) {
|
123
122
|
return true;
|
124
123
|
}
|
125
124
|
|
@@ -247,10 +246,15 @@ module.exports = function httpAdapter(config) {
|
|
247
246
|
|
248
247
|
// Handle request timeout
|
249
248
|
if (config.timeout) {
|
250
|
-
|
249
|
+
// Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
250
|
+
// And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
251
|
+
// At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
|
252
|
+
// And then these socket which be hang up will devoring CPU little by little.
|
253
|
+
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
254
|
+
req.setTimeout(config.timeout, function handleRequestTimeout() {
|
251
255
|
req.abort();
|
252
256
|
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
|
253
|
-
}
|
257
|
+
});
|
254
258
|
}
|
255
259
|
|
256
260
|
if (config.cancelToken) {
|
package/lib/adapters/xhr.js
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
var utils = require('./../utils');
|
4
4
|
var settle = require('./../core/settle');
|
5
5
|
var buildURL = require('./../helpers/buildURL');
|
6
|
+
var buildFullPath = require('../core/buildFullPath');
|
6
7
|
var parseHeaders = require('./../helpers/parseHeaders');
|
7
8
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
8
9
|
var createError = require('../core/createError');
|
@@ -25,7 +26,8 @@ module.exports = function xhrAdapter(config) {
|
|
25
26
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
26
27
|
}
|
27
28
|
|
28
|
-
|
29
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
30
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
29
31
|
|
30
32
|
// Set the request timeout in MS
|
31
33
|
request.timeout = config.timeout;
|
@@ -86,7 +88,11 @@ module.exports = function xhrAdapter(config) {
|
|
86
88
|
|
87
89
|
// Handle timeout
|
88
90
|
request.ontimeout = function handleTimeout() {
|
89
|
-
|
91
|
+
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
|
92
|
+
if (config.timeoutErrorMessage) {
|
93
|
+
timeoutErrorMessage = config.timeoutErrorMessage;
|
94
|
+
}
|
95
|
+
reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
|
90
96
|
request));
|
91
97
|
|
92
98
|
// Clean up request
|
@@ -100,7 +106,7 @@ module.exports = function xhrAdapter(config) {
|
|
100
106
|
var cookies = require('./../helpers/cookies');
|
101
107
|
|
102
108
|
// Add xsrf header
|
103
|
-
var xsrfValue = (config.withCredentials || isURLSameOrigin(
|
109
|
+
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
104
110
|
cookies.read(config.xsrfCookieName) :
|
105
111
|
undefined;
|
106
112
|
|
@@ -123,8 +129,8 @@ module.exports = function xhrAdapter(config) {
|
|
123
129
|
}
|
124
130
|
|
125
131
|
// Add withCredentials to request if needed
|
126
|
-
if (config.withCredentials) {
|
127
|
-
request.withCredentials =
|
132
|
+
if (!utils.isUndefined(config.withCredentials)) {
|
133
|
+
request.withCredentials = !!config.withCredentials;
|
128
134
|
}
|
129
135
|
|
130
136
|
// Add responseType to request if needed
|
package/lib/core/Axios.js
CHANGED
@@ -35,7 +35,15 @@ Axios.prototype.request = function request(config) {
|
|
35
35
|
}
|
36
36
|
|
37
37
|
config = mergeConfig(this.defaults, config);
|
38
|
-
|
38
|
+
|
39
|
+
// Set config.method
|
40
|
+
if (config.method) {
|
41
|
+
config.method = config.method.toLowerCase();
|
42
|
+
} else if (this.defaults.method) {
|
43
|
+
config.method = this.defaults.method.toLowerCase();
|
44
|
+
} else {
|
45
|
+
config.method = 'get';
|
46
|
+
}
|
39
47
|
|
40
48
|
// Hook up interceptors middleware
|
41
49
|
var chain = [dispatchRequest, undefined];
|
@@ -0,0 +1,20 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var isAbsoluteURL = require('../helpers/isAbsoluteURL');
|
4
|
+
var combineURLs = require('../helpers/combineURLs');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
8
|
+
* only when the requestedURL is not already an absolute URL.
|
9
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
10
|
+
*
|
11
|
+
* @param {string} baseURL The base URL
|
12
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
13
|
+
* @returns {string} The combined full path
|
14
|
+
*/
|
15
|
+
module.exports = function buildFullPath(baseURL, requestedURL) {
|
16
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
17
|
+
return combineURLs(baseURL, requestedURL);
|
18
|
+
}
|
19
|
+
return requestedURL;
|
20
|
+
};
|
@@ -4,8 +4,6 @@ var utils = require('./../utils');
|
|
4
4
|
var transformData = require('./transformData');
|
5
5
|
var isCancel = require('../cancel/isCancel');
|
6
6
|
var defaults = require('../defaults');
|
7
|
-
var isAbsoluteURL = require('./../helpers/isAbsoluteURL');
|
8
|
-
var combineURLs = require('./../helpers/combineURLs');
|
9
7
|
|
10
8
|
/**
|
11
9
|
* Throws a `Cancel` if cancellation has been requested.
|
@@ -25,11 +23,6 @@ function throwIfCancellationRequested(config) {
|
|
25
23
|
module.exports = function dispatchRequest(config) {
|
26
24
|
throwIfCancellationRequested(config);
|
27
25
|
|
28
|
-
// Support baseURL config
|
29
|
-
if (config.baseURL && !isAbsoluteURL(config.url)) {
|
30
|
-
config.url = combineURLs(config.baseURL, config.url);
|
31
|
-
}
|
32
|
-
|
33
26
|
// Ensure headers exist
|
34
27
|
config.headers = config.headers || {};
|
35
28
|
|
@@ -44,7 +37,7 @@ module.exports = function dispatchRequest(config) {
|
|
44
37
|
config.headers = utils.merge(
|
45
38
|
config.headers.common || {},
|
46
39
|
config.headers[config.method] || {},
|
47
|
-
config.headers
|
40
|
+
config.headers
|
48
41
|
);
|
49
42
|
|
50
43
|
utils.forEach(
|
package/lib/core/mergeConfig.js
CHANGED
@@ -15,13 +15,23 @@ module.exports = function mergeConfig(config1, config2) {
|
|
15
15
|
config2 = config2 || {};
|
16
16
|
var config = {};
|
17
17
|
|
18
|
-
|
18
|
+
var valueFromConfig2Keys = ['url', 'method', 'params', 'data'];
|
19
|
+
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy'];
|
20
|
+
var defaultToConfig2Keys = [
|
21
|
+
'baseURL', 'url', 'transformRequest', 'transformResponse', 'paramsSerializer',
|
22
|
+
'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
|
23
|
+
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress',
|
24
|
+
'maxContentLength', 'validateStatus', 'maxRedirects', 'httpAgent',
|
25
|
+
'httpsAgent', 'cancelToken', 'socketPath'
|
26
|
+
];
|
27
|
+
|
28
|
+
utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
|
19
29
|
if (typeof config2[prop] !== 'undefined') {
|
20
30
|
config[prop] = config2[prop];
|
21
31
|
}
|
22
32
|
});
|
23
33
|
|
24
|
-
utils.forEach(
|
34
|
+
utils.forEach(mergeDeepPropertiesKeys, function mergeDeepProperties(prop) {
|
25
35
|
if (utils.isObject(config2[prop])) {
|
26
36
|
config[prop] = utils.deepMerge(config1[prop], config2[prop]);
|
27
37
|
} else if (typeof config2[prop] !== 'undefined') {
|
@@ -33,13 +43,25 @@ module.exports = function mergeConfig(config1, config2) {
|
|
33
43
|
}
|
34
44
|
});
|
35
45
|
|
36
|
-
utils.forEach(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
46
|
+
utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
|
47
|
+
if (typeof config2[prop] !== 'undefined') {
|
48
|
+
config[prop] = config2[prop];
|
49
|
+
} else if (typeof config1[prop] !== 'undefined') {
|
50
|
+
config[prop] = config1[prop];
|
51
|
+
}
|
52
|
+
});
|
53
|
+
|
54
|
+
var axiosKeys = valueFromConfig2Keys
|
55
|
+
.concat(mergeDeepPropertiesKeys)
|
56
|
+
.concat(defaultToConfig2Keys);
|
57
|
+
|
58
|
+
var otherKeys = Object
|
59
|
+
.keys(config2)
|
60
|
+
.filter(function filterAxiosKeys(key) {
|
61
|
+
return axiosKeys.indexOf(key) === -1;
|
62
|
+
});
|
63
|
+
|
64
|
+
utils.forEach(otherKeys, function otherKeysDefaultToConfig2(prop) {
|
43
65
|
if (typeof config2[prop] !== 'undefined') {
|
44
66
|
config[prop] = config2[prop];
|
45
67
|
} else if (typeof config1[prop] !== 'undefined') {
|
package/lib/defaults.js
CHANGED
@@ -15,13 +15,12 @@ function setContentTypeIfUnset(headers, value) {
|
|
15
15
|
|
16
16
|
function getDefaultAdapter() {
|
17
17
|
var adapter;
|
18
|
-
|
19
|
-
if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
20
|
-
// For node use HTTP adapter
|
21
|
-
adapter = require('./adapters/http');
|
22
|
-
} else if (typeof XMLHttpRequest !== 'undefined') {
|
18
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
23
19
|
// For browsers use XHR adapter
|
24
20
|
adapter = require('./adapters/xhr');
|
21
|
+
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
22
|
+
// For node use HTTP adapter
|
23
|
+
adapter = require('./adapters/http');
|
25
24
|
}
|
26
25
|
return adapter;
|
27
26
|
}
|
@@ -1,6 +1,7 @@
|
|
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() ?
|
@@ -21,6 +22,10 @@ module.exports = (
|
|
21
22
|
function resolveURL(url) {
|
22
23
|
var href = url;
|
23
24
|
|
25
|
+
if (isValidXss(url)) {
|
26
|
+
throw new Error('URL contains XSS injection attempt');
|
27
|
+
}
|
28
|
+
|
24
29
|
if (msie) {
|
25
30
|
// IE needs attribute set twice to normalize properties
|
26
31
|
urlParsingNode.setAttribute('href', href);
|
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
|
*
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "0.19.
|
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": {
|
@@ -73,8 +73,7 @@
|
|
73
73
|
},
|
74
74
|
"typings": "./index.d.ts",
|
75
75
|
"dependencies": {
|
76
|
-
"follow-redirects": "1.5.10"
|
77
|
-
"is-buffer": "^2.0.2"
|
76
|
+
"follow-redirects": "1.5.10"
|
78
77
|
},
|
79
78
|
"bundlesize": [
|
80
79
|
{
|