axios 0.21.0 → 0.21.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 +23 -0
- package/README.md +3 -1
- package/dist/axios.js +21 -1
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -2
- package/dist/axios.min.map +1 -1
- package/index.d.ts +3 -2
- package/lib/adapters/http.js +28 -12
- package/lib/axios.js +3 -0
- package/lib/helpers/isAxiosError.js +11 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
@@ -153,8 +153,9 @@ export interface AxiosStatic extends AxiosInstance {
|
|
153
153
|
isCancel(value: any): boolean;
|
154
154
|
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
|
155
155
|
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
156
|
+
isAxiosError(payload: any): payload is AxiosError;
|
156
157
|
}
|
157
158
|
|
158
|
-
declare const
|
159
|
+
declare const axios: AxiosStatic;
|
159
160
|
|
160
|
-
export default
|
161
|
+
export default axios;
|
package/lib/adapters/http.js
CHANGED
@@ -16,6 +16,31 @@ var enhanceError = require('../core/enhanceError');
|
|
16
16
|
|
17
17
|
var isHttps = /https:?/;
|
18
18
|
|
19
|
+
/**
|
20
|
+
*
|
21
|
+
* @param {http.ClientRequestArgs} options
|
22
|
+
* @param {AxiosProxyConfig} proxy
|
23
|
+
* @param {string} location
|
24
|
+
*/
|
25
|
+
function setProxy(options, proxy, location) {
|
26
|
+
options.hostname = proxy.host;
|
27
|
+
options.host = proxy.host;
|
28
|
+
options.port = proxy.port;
|
29
|
+
options.path = location;
|
30
|
+
|
31
|
+
// Basic proxy authorization
|
32
|
+
if (proxy.auth) {
|
33
|
+
var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
34
|
+
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
35
|
+
}
|
36
|
+
|
37
|
+
// If a proxy is used, any redirects must also pass through the proxy
|
38
|
+
options.beforeRedirect = function beforeRedirect(redirection) {
|
39
|
+
redirection.headers.host = redirection.host;
|
40
|
+
setProxy(redirection, proxy, redirection.href);
|
41
|
+
};
|
42
|
+
}
|
43
|
+
|
19
44
|
/*eslint consistent-return:0*/
|
20
45
|
module.exports = function httpAdapter(config) {
|
21
46
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
@@ -126,11 +151,11 @@ module.exports = function httpAdapter(config) {
|
|
126
151
|
});
|
127
152
|
}
|
128
153
|
|
129
|
-
|
130
154
|
if (shouldProxy) {
|
131
155
|
proxy = {
|
132
156
|
host: parsedProxyUrl.hostname,
|
133
|
-
port: parsedProxyUrl.port
|
157
|
+
port: parsedProxyUrl.port,
|
158
|
+
protocol: parsedProxyUrl.protocol
|
134
159
|
};
|
135
160
|
|
136
161
|
if (parsedProxyUrl.auth) {
|
@@ -145,17 +170,8 @@ module.exports = function httpAdapter(config) {
|
|
145
170
|
}
|
146
171
|
|
147
172
|
if (proxy) {
|
148
|
-
options.hostname = proxy.host;
|
149
|
-
options.host = proxy.host;
|
150
173
|
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
151
|
-
options.port
|
152
|
-
options.path = protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path;
|
153
|
-
|
154
|
-
// Basic proxy authorization
|
155
|
-
if (proxy.auth) {
|
156
|
-
var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
157
|
-
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
158
|
-
}
|
174
|
+
setProxy(options, proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
|
159
175
|
}
|
160
176
|
|
161
177
|
var transport;
|
package/lib/axios.js
CHANGED
@@ -47,6 +47,9 @@ axios.all = function all(promises) {
|
|
47
47
|
};
|
48
48
|
axios.spread = require('./helpers/spread');
|
49
49
|
|
50
|
+
// Expose isAxiosError
|
51
|
+
axios.isAxiosError = require('./helpers/isAxiosError');
|
52
|
+
|
50
53
|
module.exports = axios;
|
51
54
|
|
52
55
|
// Allow use of default import syntax in TypeScript
|
@@ -0,0 +1,11 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Determines whether the payload is an error thrown by Axios
|
5
|
+
*
|
6
|
+
* @param {*} payload The value to test
|
7
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
8
|
+
*/
|
9
|
+
module.exports = function isAxiosError(payload) {
|
10
|
+
return (typeof payload === 'object') && (payload.isAxiosError === true);
|
11
|
+
};
|