axios 0.30.2 → 0.31.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.
- package/dist/axios.js +42 -4
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +42 -4
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/index.d.ts +2 -2
- package/lib/adapters/http.js +7 -4
- package/lib/core/dispatchRequest.js +5 -0
- package/lib/core/mergeConfig.js +4 -1
- package/lib/env/data.js +1 -1
- package/lib/helpers/sanitizeHeaderValue.js +22 -0
- package/lib/helpers/shouldBypassProxy.js +133 -0
- package/lib/utils.js +13 -1
- package/mise.toml +1 -1
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ var isCancel = require('../cancel/isCancel');
|
|
|
6
6
|
var defaults = require('../defaults');
|
|
7
7
|
var CanceledError = require('../cancel/CanceledError');
|
|
8
8
|
var normalizeHeaderName = require('../helpers/normalizeHeaderName');
|
|
9
|
+
var sanitizeHeaderValue = require('../helpers/sanitizeHeaderValue');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Throws a `CanceledError` if cancellation has been requested.
|
|
@@ -58,6 +59,10 @@ module.exports = function dispatchRequest(config) {
|
|
|
58
59
|
}
|
|
59
60
|
);
|
|
60
61
|
|
|
62
|
+
utils.forEach(config.headers, function sanitizeHeaderConfigValue(value, header) {
|
|
63
|
+
config.headers[header] = sanitizeHeaderValue(value);
|
|
64
|
+
});
|
|
65
|
+
|
|
61
66
|
var adapter = config.adapter || defaults.adapter;
|
|
62
67
|
|
|
63
68
|
return adapter(config).then(function onAdapterResolution(response) {
|
package/lib/core/mergeConfig.js
CHANGED
|
@@ -94,7 +94,10 @@ module.exports = function mergeConfig(config1, config2) {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
|
97
|
-
|
|
97
|
+
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
var merge = utils.hasOwnProperty(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
|
|
98
101
|
var configValue = merge(prop);
|
|
99
102
|
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
100
103
|
});
|
package/lib/env/data.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('../utils');
|
|
4
|
+
|
|
5
|
+
var INVALID_HEADER_VALUE_RE = /[^\x09\x20-\x7E\x80-\xFF]/g;
|
|
6
|
+
var BOUNDARY_WHITESPACE_RE = /^[\x09\x20]+|[\x09\x20]+$/g;
|
|
7
|
+
|
|
8
|
+
function sanitizeHeaderValue(value) {
|
|
9
|
+
if (value === false || value == null) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (utils.isArray(value)) {
|
|
14
|
+
return value.map(sanitizeHeaderValue);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return String(value)
|
|
18
|
+
.replace(INVALID_HEADER_VALUE_RE, '')
|
|
19
|
+
.replace(BOUNDARY_WHITESPACE_RE, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = sanitizeHeaderValue;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var URL = require('url').URL;
|
|
4
|
+
|
|
5
|
+
var DEFAULT_PORTS = {
|
|
6
|
+
http: 80,
|
|
7
|
+
https: 443,
|
|
8
|
+
ws: 80,
|
|
9
|
+
wss: 443,
|
|
10
|
+
ftp: 21
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function parseNoProxyEntry(entry) {
|
|
14
|
+
var entryHost = entry;
|
|
15
|
+
var entryPort = 0;
|
|
16
|
+
|
|
17
|
+
if (entryHost.charAt(0) === '[') {
|
|
18
|
+
var bracketIndex = entryHost.indexOf(']');
|
|
19
|
+
|
|
20
|
+
if (bracketIndex !== -1) {
|
|
21
|
+
var host = entryHost.slice(1, bracketIndex);
|
|
22
|
+
var rest = entryHost.slice(bracketIndex + 1);
|
|
23
|
+
|
|
24
|
+
if (rest.charAt(0) === ':' && /^\d+$/.test(rest.slice(1))) {
|
|
25
|
+
entryPort = parseInt(rest.slice(1), 10);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return [host, entryPort];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var firstColon = entryHost.indexOf(':');
|
|
33
|
+
var lastColon = entryHost.lastIndexOf(':');
|
|
34
|
+
|
|
35
|
+
if (firstColon !== -1 && firstColon === lastColon && /^\d+$/.test(entryHost.slice(lastColon + 1))) {
|
|
36
|
+
entryPort = parseInt(entryHost.slice(lastColon + 1), 10);
|
|
37
|
+
entryHost = entryHost.slice(0, lastColon);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return [entryHost, entryPort];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function normalizeNoProxyHost(hostname) {
|
|
44
|
+
if (!hostname) {
|
|
45
|
+
return hostname;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (hostname.charAt(0) === '[' && hostname.charAt(hostname.length - 1) === ']') {
|
|
49
|
+
hostname = hostname.slice(1, -1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return hostname.replace(/\.+$/, '');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isLoopbackIPv4(hostname) {
|
|
56
|
+
var octets = hostname.split('.');
|
|
57
|
+
|
|
58
|
+
if (octets.length !== 4) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (octets[0] !== '127') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return octets.every(function testOctet(octet) {
|
|
67
|
+
return /^\d+$/.test(octet) && Number(octet) >= 0 && Number(octet) <= 255;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function isLoopbackHost(hostname) {
|
|
72
|
+
return hostname === 'localhost' || hostname === '::1' || isLoopbackIPv4(hostname);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = function shouldBypassProxy(location) {
|
|
76
|
+
var parsed;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
parsed = new URL(location);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
|
|
85
|
+
|
|
86
|
+
if (!noProxy) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (noProxy === '*') {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
var protocol = parsed.protocol.split(':', 1)[0];
|
|
95
|
+
var port = parsed.port !== '' ? parseInt(parsed.port, 10) : (DEFAULT_PORTS[protocol] || 0);
|
|
96
|
+
var hostname = normalizeNoProxyHost(parsed.hostname.toLowerCase());
|
|
97
|
+
|
|
98
|
+
return noProxy.split(/[\s,]+/).some(function testNoProxyEntry(entry) {
|
|
99
|
+
if (!entry) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var entryParts = parseNoProxyEntry(entry);
|
|
104
|
+
var entryHost = normalizeNoProxyHost(entryParts[0]);
|
|
105
|
+
var entryPort = entryParts[1];
|
|
106
|
+
|
|
107
|
+
if (entryHost === '*') {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!entryHost) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (entryPort && entryPort !== port) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (isLoopbackHost(hostname) && isLoopbackHost(entryHost)) {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (entryHost.charAt(0) === '*') {
|
|
124
|
+
entryHost = entryHost.slice(1);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (entryHost.charAt(0) === '.') {
|
|
128
|
+
return hostname.slice(-entryHost.length) === entryHost;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return hostname === entryHost;
|
|
132
|
+
});
|
|
133
|
+
};
|
package/lib/utils.js
CHANGED
|
@@ -131,7 +131,15 @@ function isPlainObject(val) {
|
|
|
131
131
|
* @return {boolean} True if value is a empty Object, otherwise false
|
|
132
132
|
*/
|
|
133
133
|
function isEmptyObject(val) {
|
|
134
|
-
|
|
134
|
+
if (!isPlainObject(val)) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
for (var key in val) {
|
|
138
|
+
if (Object.prototype.hasOwnProperty.call(val, key)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
135
143
|
}
|
|
136
144
|
|
|
137
145
|
/**
|
|
@@ -310,6 +318,10 @@ function forEach(obj, fn) {
|
|
|
310
318
|
function merge(/* obj1, obj2, obj3, ... */) {
|
|
311
319
|
var result = {};
|
|
312
320
|
function assignValue(val, key) {
|
|
321
|
+
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
313
325
|
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
|
314
326
|
result[key] = merge(result[key], val);
|
|
315
327
|
} else if (isPlainObject(val)) {
|
package/mise.toml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
[tools]
|
|
2
|
-
node = "
|
|
2
|
+
node = "20"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axios",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"body-parser": "^1.20.0",
|
|
41
41
|
"coveralls": "^3.1.1",
|
|
42
42
|
"cross-env": "^7.0.3",
|
|
43
|
-
"dtslint": "
|
|
43
|
+
"dtslint": "4.2.1",
|
|
44
44
|
"es6-promise": "^4.2.8",
|
|
45
45
|
"express": "^4.18.1",
|
|
46
46
|
"formidable": "^2.0.1",
|