axios 0.34.0 → 0.35.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 +241 -25
- 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 +241 -25
- 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/lib/adapters/http.js +53 -9
- package/lib/core/Axios.js +29 -14
- package/lib/core/mergeConfig.js +3 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/assertParamsDepth.js +100 -0
- package/lib/helpers/estimateDataURLDecodedBytes.js +3 -3
- package/lib/helpers/formDataToJSON.js +40 -3
- package/lib/helpers/getDirectAgent.js +85 -0
- package/lib/helpers/shouldBypassProxy.js +17 -1
- package/lib/helpers/toFormData.js +4 -4
- package/lib/utils.js +68 -2
- package/package.json +1 -1
package/lib/adapters/http.js
CHANGED
|
@@ -21,6 +21,7 @@ var fromDataURI = require('../helpers/fromDataURI');
|
|
|
21
21
|
var stream = require('stream');
|
|
22
22
|
var estimateDataURLDecodedBytes = require('../helpers/estimateDataURLDecodedBytes.js');
|
|
23
23
|
var shouldBypassProxy = require('../helpers/shouldBypassProxy');
|
|
24
|
+
var getDirectAgent = require('../helpers/getDirectAgent');
|
|
24
25
|
|
|
25
26
|
var isHttps = /https:?/;
|
|
26
27
|
|
|
@@ -28,15 +29,39 @@ var supportedProtocols = platform.protocols.map(function(protocol) {
|
|
|
28
29
|
return protocol + ':';
|
|
29
30
|
});
|
|
30
31
|
|
|
31
|
-
function dispatchBeforeRedirect(options) {
|
|
32
|
+
function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
|
|
33
|
+
var sameOrigin = false;
|
|
34
|
+
try {
|
|
35
|
+
sameOrigin = new url.URL(requestDetails.url).origin === new url.URL(options.href).origin;
|
|
36
|
+
} catch (err) {
|
|
37
|
+
// Leave the comparison false when either URL is unavailable.
|
|
38
|
+
}
|
|
39
|
+
if (!sameOrigin) {
|
|
40
|
+
Object.keys(options.headers).forEach(function(header) {
|
|
41
|
+
if (/^(authorization|cookie)$/i.test(header)) {
|
|
42
|
+
delete options.headers[header];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
delete options.auth;
|
|
46
|
+
}
|
|
32
47
|
if (options.beforeRedirects.proxy) {
|
|
33
48
|
options.beforeRedirects.proxy(options);
|
|
34
49
|
}
|
|
50
|
+
if (options.beforeRedirects.direct) {
|
|
51
|
+
options.beforeRedirects.direct(options);
|
|
52
|
+
}
|
|
35
53
|
if (options.beforeRedirects.config) {
|
|
36
54
|
options.beforeRedirects.config(options);
|
|
37
55
|
}
|
|
38
56
|
}
|
|
39
57
|
|
|
58
|
+
function setDirectAgent(options, httpAgent, httpsAgent) {
|
|
59
|
+
var secure = isHttps.test(options.protocol);
|
|
60
|
+
var agent = getDirectAgent(secure ? httpsAgent : httpAgent, secure ? https : http);
|
|
61
|
+
options.agent = agent;
|
|
62
|
+
options.agents[secure ? 'https' : 'http'] = agent;
|
|
63
|
+
}
|
|
64
|
+
|
|
40
65
|
function removeProxyAuthorization(headers) {
|
|
41
66
|
Object.keys(headers).forEach(function removeHeader(header) {
|
|
42
67
|
if (header.toLowerCase() === 'proxy-authorization') {
|
|
@@ -317,6 +342,18 @@ module.exports = function httpAdapter(config) {
|
|
|
317
342
|
throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
|
|
318
343
|
}
|
|
319
344
|
|
|
345
|
+
// Check bytes before converting the result to text or a stream.
|
|
346
|
+
if (config.maxContentLength > -1 &&
|
|
347
|
+
(responseType === 'blob' ? convertedData.size : convertedData.length) > config.maxContentLength) {
|
|
348
|
+
return reject(
|
|
349
|
+
new AxiosError(
|
|
350
|
+
'maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
|
351
|
+
AxiosError.ERR_BAD_RESPONSE,
|
|
352
|
+
config
|
|
353
|
+
)
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
320
357
|
if (responseType === 'text') {
|
|
321
358
|
convertedData = convertedData.toString(responseEncoding);
|
|
322
359
|
|
|
@@ -451,6 +488,9 @@ module.exports = function httpAdapter(config) {
|
|
|
451
488
|
reject(customErr);
|
|
452
489
|
}
|
|
453
490
|
|
|
491
|
+
var configProxy = utils.hasOwnProperty(config, 'proxy') ? config.proxy : undefined;
|
|
492
|
+
var httpAgent = config.httpAgent;
|
|
493
|
+
var httpsAgent = config.httpsAgent;
|
|
454
494
|
var options = {
|
|
455
495
|
path: buildURL(
|
|
456
496
|
parsed.path,
|
|
@@ -459,7 +499,7 @@ module.exports = function httpAdapter(config) {
|
|
|
459
499
|
).replace(/^\?/, ''),
|
|
460
500
|
method: method,
|
|
461
501
|
headers: headers,
|
|
462
|
-
agents: { http:
|
|
502
|
+
agents: { http: httpAgent, https: httpsAgent },
|
|
463
503
|
auth: auth,
|
|
464
504
|
protocol: protocol,
|
|
465
505
|
beforeRedirect: dispatchBeforeRedirect,
|
|
@@ -480,7 +520,6 @@ module.exports = function httpAdapter(config) {
|
|
|
480
520
|
} else {
|
|
481
521
|
options.hostname = parsed.hostname;
|
|
482
522
|
options.port = parsed.port;
|
|
483
|
-
var configProxy = utils.hasOwnProperty(config, 'proxy') ? config.proxy : undefined;
|
|
484
523
|
setProxy(
|
|
485
524
|
options,
|
|
486
525
|
configProxy,
|
|
@@ -490,7 +529,14 @@ module.exports = function httpAdapter(config) {
|
|
|
490
529
|
|
|
491
530
|
var transport;
|
|
492
531
|
var isHttpsRequest = isHttps.test(options.protocol);
|
|
493
|
-
|
|
532
|
+
if (configProxy === false) {
|
|
533
|
+
setDirectAgent(options, httpAgent, httpsAgent);
|
|
534
|
+
options.beforeRedirects.direct = function(redirectOptions) {
|
|
535
|
+
setDirectAgent(redirectOptions, httpAgent, httpsAgent);
|
|
536
|
+
};
|
|
537
|
+
} else {
|
|
538
|
+
options.agent = isHttpsRequest ? httpsAgent : httpAgent;
|
|
539
|
+
}
|
|
494
540
|
if (utils.hasOwnProperty(config, 'transport') && config.transport) {
|
|
495
541
|
transport = config.transport;
|
|
496
542
|
} else if (config.maxRedirects === 0) {
|
|
@@ -769,11 +815,9 @@ module.exports = function httpAdapter(config) {
|
|
|
769
815
|
reject(AxiosError.from(err, config, null, req));
|
|
770
816
|
});
|
|
771
817
|
|
|
772
|
-
//
|
|
773
|
-
//
|
|
774
|
-
|
|
775
|
-
var nativeTransport = transport === http || transport === https;
|
|
776
|
-
if (nativeTransport && config.maxBodyLength > -1) {
|
|
818
|
+
// Transform decodes string chunks to Buffers before counting, so every
|
|
819
|
+
// transport receives at most maxBodyLength encoded bytes.
|
|
820
|
+
if (config.maxBodyLength > -1) {
|
|
777
821
|
var maxBodyLength = config.maxBodyLength;
|
|
778
822
|
var uploadedBytes = 0;
|
|
779
823
|
var bodyLimiter = new stream.Transform({
|
package/lib/core/Axios.js
CHANGED
|
@@ -88,7 +88,11 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
|
88
88
|
config = configOrUrl || {};
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
|
|
91
|
+
try {
|
|
92
|
+
config = mergeConfig(this.defaults, config);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
return Promise.reject(error);
|
|
95
|
+
}
|
|
92
96
|
var caller = config.captureCallerStack === true ? captureCallerStack(request) : null;
|
|
93
97
|
|
|
94
98
|
// Set config.method. The merged config is null-prototype, but instance
|
|
@@ -214,11 +218,16 @@ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData
|
|
|
214
218
|
Axios.prototype[method] = function(url, config) {
|
|
215
219
|
var requestConfig = config || {};
|
|
216
220
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
221
|
+
try {
|
|
222
|
+
requestConfig = mergeConfig(requestConfig, {
|
|
223
|
+
method: method,
|
|
224
|
+
url: url,
|
|
225
|
+
data: utils.hasOwnProperty(requestConfig, 'data') ? requestConfig.data : undefined
|
|
226
|
+
});
|
|
227
|
+
} catch (error) {
|
|
228
|
+
return Promise.reject(error);
|
|
229
|
+
}
|
|
230
|
+
return this.request(requestConfig);
|
|
222
231
|
};
|
|
223
232
|
});
|
|
224
233
|
|
|
@@ -227,14 +236,20 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
|
227
236
|
|
|
228
237
|
function generateHTTPMethod(isForm) {
|
|
229
238
|
return function httpMethod(url, data, config) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
239
|
+
var requestConfig;
|
|
240
|
+
try {
|
|
241
|
+
requestConfig = mergeConfig(config || {}, {
|
|
242
|
+
method: method,
|
|
243
|
+
headers: isForm ? {
|
|
244
|
+
'Content-Type': 'multipart/form-data'
|
|
245
|
+
} : {},
|
|
246
|
+
url: url,
|
|
247
|
+
data: data
|
|
248
|
+
});
|
|
249
|
+
} catch (error) {
|
|
250
|
+
return Promise.reject(error);
|
|
251
|
+
}
|
|
252
|
+
return this.request(requestConfig);
|
|
238
253
|
};
|
|
239
254
|
}
|
|
240
255
|
|
package/lib/core/mergeConfig.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var utils = require('../utils');
|
|
4
|
+
var assertParamsDepth = require('../helpers/assertParamsDepth');
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Config-specific merge-function which creates a new config-object
|
|
@@ -13,6 +14,8 @@ var utils = require('../utils');
|
|
|
13
14
|
module.exports = function mergeConfig(config1, config2) {
|
|
14
15
|
// eslint-disable-next-line no-param-reassign
|
|
15
16
|
config2 = config2 || {};
|
|
17
|
+
assertParamsDepth(utils.hasOwnProperty(config1, 'params') ? config1.params : undefined);
|
|
18
|
+
assertParamsDepth(utils.hasOwnProperty(config2, 'params') ? config2.params : undefined);
|
|
16
19
|
// Use a null-prototype object so a polluted Object.prototype cannot leak
|
|
17
20
|
// values (e.g. transport, adapter) into the returned config via inheritance.
|
|
18
21
|
var config = Object.create(null);
|
package/lib/env/data.js
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('../utils');
|
|
4
|
+
var AxiosError = require('../core/AxiosError');
|
|
5
|
+
|
|
6
|
+
// Match numeric array reads without scanning unoccupied slots or metadata.
|
|
7
|
+
function arrayIndexes(array) {
|
|
8
|
+
var length = array.length;
|
|
9
|
+
var indexes = Object.create(null);
|
|
10
|
+
var keys = [];
|
|
11
|
+
var source = array;
|
|
12
|
+
var fast = array;
|
|
13
|
+
while (source) {
|
|
14
|
+
var names = Object.getOwnPropertyNames(source);
|
|
15
|
+
for (var i = 0; i < names.length; i++) {
|
|
16
|
+
var key = names[i];
|
|
17
|
+
var index = +key;
|
|
18
|
+
if (index >= 0 && index < length && Math.floor(index) === index &&
|
|
19
|
+
String(index) === key && !indexes[key]) {
|
|
20
|
+
indexes[key] = true;
|
|
21
|
+
keys.push(key);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
source = Object.getPrototypeOf(source);
|
|
25
|
+
// Detect unusual cyclic prototype chains with constant memory.
|
|
26
|
+
fast = fast && Object.getPrototypeOf(fast);
|
|
27
|
+
fast = fast && Object.getPrototypeOf(fast);
|
|
28
|
+
if (source && source === fast) {
|
|
29
|
+
throw new AxiosError('Circular prototype chain in params', AxiosError.ERR_BAD_OPTION_VALUE);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return keys.sort(function(a, b) { return a - b; });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = function assertParamsDepth(params) {
|
|
36
|
+
if (!utils.isObject(params)) return;
|
|
37
|
+
var pending = [{ value: params, depth: 0, complete: false }];
|
|
38
|
+
var ancestors = [];
|
|
39
|
+
var visited = null;
|
|
40
|
+
if (typeof WeakMap === 'function') {
|
|
41
|
+
visited = new WeakMap();
|
|
42
|
+
} else if (typeof Map === 'function') {
|
|
43
|
+
visited = new Map();
|
|
44
|
+
}
|
|
45
|
+
// Older runtimes can only compare immutable object identities by scanning.
|
|
46
|
+
// Keep that scan bounded; recently completed subgraphs avoid repeated work,
|
|
47
|
+
// while evicted shared subgraphs may be visited again.
|
|
48
|
+
var cacheSize = 128;
|
|
49
|
+
var visitedValues = [];
|
|
50
|
+
var visitedDepths = [];
|
|
51
|
+
var nextCacheIndex = 0;
|
|
52
|
+
while (pending.length) {
|
|
53
|
+
var entry = pending.pop();
|
|
54
|
+
var value = entry.value;
|
|
55
|
+
var index;
|
|
56
|
+
if (entry.complete) {
|
|
57
|
+
ancestors.pop();
|
|
58
|
+
if (visited) {
|
|
59
|
+
visited.set(value, entry.depth);
|
|
60
|
+
} else {
|
|
61
|
+
index = visitedValues.indexOf(value);
|
|
62
|
+
if (index === -1) {
|
|
63
|
+
index = nextCacheIndex;
|
|
64
|
+
nextCacheIndex = (nextCacheIndex + 1) % cacheSize;
|
|
65
|
+
}
|
|
66
|
+
visitedValues[index] = value;
|
|
67
|
+
visitedDepths[index] = entry.depth;
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
// The serializer enumerates any object at its root, then recursively
|
|
72
|
+
// visits only plain objects and arrays below that root.
|
|
73
|
+
if (entry.depth === 0 ? !utils.isObject(value) :
|
|
74
|
+
!utils.isPlainObject(value) && !utils.isArray(value)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (entry.depth > 100) {
|
|
78
|
+
throw new AxiosError('params exceed the maximum depth of 100', AxiosError.ERR_BAD_OPTION_VALUE);
|
|
79
|
+
}
|
|
80
|
+
// The depth cap bounds this ancestry scan independently of params width.
|
|
81
|
+
if (ancestors.indexOf(value) !== -1) {
|
|
82
|
+
throw new AxiosError('Circular reference detected in params', AxiosError.ERR_BAD_OPTION_VALUE);
|
|
83
|
+
}
|
|
84
|
+
if (visited) {
|
|
85
|
+
if (visited.has(value) && visited.get(value) >= entry.depth) continue;
|
|
86
|
+
} else {
|
|
87
|
+
index = visitedValues.indexOf(value);
|
|
88
|
+
if (index !== -1 && visitedDepths[index] >= entry.depth) continue;
|
|
89
|
+
}
|
|
90
|
+
ancestors.push(value);
|
|
91
|
+
pending.push({ value: value, depth: entry.depth, complete: true });
|
|
92
|
+
var keys = utils.isArray(value) ? arrayIndexes(value) : Object.keys(value);
|
|
93
|
+
for (var i = 0; i < keys.length; i++) {
|
|
94
|
+
var key = keys[i];
|
|
95
|
+
if (key !== '__proto__' && key !== 'constructor' && key !== 'prototype') {
|
|
96
|
+
pending.push({ value: value[key], depth: entry.depth + 1, complete: false });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
};
|
|
@@ -18,7 +18,8 @@ function estimateDataURLDecodedBytes(url) {
|
|
|
18
18
|
|
|
19
19
|
var meta = url.slice(5, comma);
|
|
20
20
|
var body = url.slice(comma + 1);
|
|
21
|
-
|
|
21
|
+
// Match the exact encoding suffix accepted by fromDataURI.
|
|
22
|
+
var isBase64 = /(?:^|;)base64$/.test(meta);
|
|
22
23
|
|
|
23
24
|
if (isBase64) {
|
|
24
25
|
var effectiveLen = body.length;
|
|
@@ -68,8 +69,7 @@ function estimateDataURLDecodedBytes(url) {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
var
|
|
72
|
-
var bytes = groups * 3 - (pad || 0);
|
|
72
|
+
var bytes = Math.floor((effectiveLen - pad) * 3 / 4);
|
|
73
73
|
return bytes > 0 ? bytes : 0;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -39,13 +39,50 @@ function arrayToObject(arr) {
|
|
|
39
39
|
return obj;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function normalizeArray(value) {
|
|
43
|
+
if (!utils.isArray(value)) return value;
|
|
44
|
+
|
|
45
|
+
var keys = Object.keys(value);
|
|
46
|
+
if (keys.length !== value.length) return arrayToObject(value);
|
|
47
|
+
|
|
48
|
+
for (var i = 0; i < keys.length; i++) {
|
|
49
|
+
var index = +keys[i];
|
|
50
|
+
if (
|
|
51
|
+
index < 0 || index >= value.length ||
|
|
52
|
+
Math.floor(index) !== index || String(index) !== keys[i]
|
|
53
|
+
) {
|
|
54
|
+
return arrayToObject(value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function normalizeArrays(obj) {
|
|
62
|
+
var pending = [obj];
|
|
63
|
+
function normalizeEntry(target, key) {
|
|
64
|
+
var value = target[key] = normalizeArray(target[key]);
|
|
65
|
+
if (utils.isArray(value) || utils.isPlainObject(value)) {
|
|
66
|
+
pending.push(value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
while (pending.length) {
|
|
70
|
+
var target = pending.pop();
|
|
71
|
+
var keys = Object.keys(target);
|
|
72
|
+
for (var i = 0; i < keys.length; i++) {
|
|
73
|
+
normalizeEntry(target, keys[i]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return obj;
|
|
77
|
+
}
|
|
78
|
+
|
|
42
79
|
function formDataToJSON(formData) {
|
|
43
80
|
function buildPath(path, value, target, index) {
|
|
44
81
|
var name = path[index++];
|
|
45
82
|
|
|
46
83
|
if (name === '__proto__') return true;
|
|
47
84
|
|
|
48
|
-
var isNumericKey =
|
|
85
|
+
var isNumericKey = isFinite(+name);
|
|
49
86
|
var isLast = index >= path.length;
|
|
50
87
|
name = !name && utils.isArray(target) ? target.length : name;
|
|
51
88
|
|
|
@@ -59,7 +96,7 @@ function formDataToJSON(formData) {
|
|
|
59
96
|
return !isNumericKey;
|
|
60
97
|
}
|
|
61
98
|
|
|
62
|
-
if (!target
|
|
99
|
+
if (!utils.hasOwnProperty(target, name) || !utils.isObject(target[name])) {
|
|
63
100
|
target[name] = [];
|
|
64
101
|
}
|
|
65
102
|
|
|
@@ -82,7 +119,7 @@ function formDataToJSON(formData) {
|
|
|
82
119
|
buildPath(path, value, obj, 0);
|
|
83
120
|
});
|
|
84
121
|
|
|
85
|
-
return obj;
|
|
122
|
+
return normalizeArrays(obj);
|
|
86
123
|
}
|
|
87
124
|
|
|
88
125
|
return null;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('../utils');
|
|
4
|
+
var AxiosError = require('../core/AxiosError');
|
|
5
|
+
var bind = require('./bind');
|
|
6
|
+
var directAgents = new WeakMap();
|
|
7
|
+
var directHooks = ['createConnection', 'getName'];
|
|
8
|
+
var nativePoolHooks = [
|
|
9
|
+
'addRequest', 'createSocket', 'removeSocket', 'keepSocketAlive', 'reuseSocket',
|
|
10
|
+
'_getSession', '_cacheSession', '_evictSession'
|
|
11
|
+
];
|
|
12
|
+
var agentControls = [
|
|
13
|
+
'keepAlive', 'keepAliveMsecs', 'maxSockets', 'maxFreeSockets',
|
|
14
|
+
'maxTotalSockets', 'scheduling', 'maxCachedSessions',
|
|
15
|
+
'agentKeepAliveTimeoutBuffer', 'defaultPort'
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
module.exports = function getDirectAgent(configuredAgent, transport) {
|
|
19
|
+
if (!process.allowedNodeEnvironmentFlags ||
|
|
20
|
+
!process.allowedNodeEnvironmentFlags.has('--use-env-proxy')) {
|
|
21
|
+
return configuredAgent;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var agent = configuredAgent || transport.globalAgent;
|
|
25
|
+
var options = agent && agent.options;
|
|
26
|
+
if (!(agent instanceof transport.Agent) ||
|
|
27
|
+
agent.protocol !== transport.globalAgent.protocol) {
|
|
28
|
+
return configuredAgent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Node snapshots proxyEnv at construction. Once adapted, retain the direct
|
|
32
|
+
// pool even if callers remove or replace the source's public proxy options.
|
|
33
|
+
var direct = directAgents.get(agent);
|
|
34
|
+
if (!direct && (!options || !utils.hasOwnProperty(options, 'proxyEnv') ||
|
|
35
|
+
typeof options.proxyEnv !== 'object' || options.proxyEnv === null)) {
|
|
36
|
+
return configuredAgent;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Pool lifecycle hooks mutate their receiver's queues and socket state.
|
|
40
|
+
// Binding them to the source pool or copying them without subclass state
|
|
41
|
+
// cannot preserve their behavior on an independently managed direct pool.
|
|
42
|
+
for (var i = 0; i < nativePoolHooks.length; i++) {
|
|
43
|
+
var hook = nativePoolHooks[i];
|
|
44
|
+
if (utils.isFunction(transport.Agent.prototype[hook]) && agent[hook] !== transport.Agent.prototype[hook]) {
|
|
45
|
+
throw new AxiosError(
|
|
46
|
+
'proxy: false cannot adapt an agent overriding ' + hook + '; use an agent constructed without proxyEnv',
|
|
47
|
+
AxiosError.ERR_BAD_OPTION_VALUE
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var directOptions = Object.assign(Object.create(null), options, { proxyEnv: undefined });
|
|
53
|
+
if (!direct) {
|
|
54
|
+
direct = new transport.Agent(directOptions);
|
|
55
|
+
// The configured agent remains the application's cleanup handle for both
|
|
56
|
+
// pools, including when requests are made after destroy().
|
|
57
|
+
var destroy = agent.destroy;
|
|
58
|
+
agent.destroy = function destroyWithDirectAgent() {
|
|
59
|
+
try {
|
|
60
|
+
return destroy.apply(this, arguments);
|
|
61
|
+
} finally {
|
|
62
|
+
direct.destroy();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
directAgents.set(agent, direct);
|
|
66
|
+
} else {
|
|
67
|
+
direct.options = directOptions;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// These hooks supply connections and pool keys without owning the direct
|
|
71
|
+
// pool's queues. Preserve the source receiver, including subclass state.
|
|
72
|
+
directHooks.forEach(function(key) {
|
|
73
|
+
direct[key] = agent[key] === transport.Agent.prototype[key]
|
|
74
|
+
? transport.Agent.prototype[key] : bind(agent[key], agent);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Public pool controls can change after construction or between requests.
|
|
78
|
+
// Keep the cached pool in step with the application-owned agent.
|
|
79
|
+
agentControls.forEach(function(key) {
|
|
80
|
+
if (utils.hasOwnProperty(agent, key)) {
|
|
81
|
+
direct[key] = agent[key];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return direct;
|
|
85
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var URL = require('url').URL;
|
|
4
|
+
var domainToASCII = require('url').domainToASCII;
|
|
4
5
|
|
|
5
6
|
var DEFAULT_PORTS = {
|
|
6
7
|
http: 80,
|
|
@@ -130,6 +131,20 @@ function normalizeNoProxyHost(hostname) {
|
|
|
130
131
|
|
|
131
132
|
hostname = stripTrailingDots(hostname);
|
|
132
133
|
|
|
134
|
+
if (hostname.indexOf(':') !== -1) {
|
|
135
|
+
try {
|
|
136
|
+
hostname = new URL('http://[' + hostname + ']/').hostname.slice(1, -1);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
return hostname;
|
|
139
|
+
}
|
|
140
|
+
} else if (/[\u0080-\uffff]/.test(hostname)) {
|
|
141
|
+
var prefix = /^[*.]+/.exec(hostname);
|
|
142
|
+
var start = prefix ? prefix[0] : '';
|
|
143
|
+
var ascii = domainToASCII(hostname.slice(start.length));
|
|
144
|
+
if (!ascii) return '';
|
|
145
|
+
hostname = start + stripTrailingDots(ascii);
|
|
146
|
+
}
|
|
147
|
+
|
|
133
148
|
return normalizeIPv4MappedIPv6(hostname);
|
|
134
149
|
}
|
|
135
150
|
|
|
@@ -340,7 +355,8 @@ module.exports = function shouldBypassProxy(location) {
|
|
|
340
355
|
return false;
|
|
341
356
|
}
|
|
342
357
|
|
|
343
|
-
var noProxy = (process.env.
|
|
358
|
+
var noProxy = (process.env.npm_config_no_proxy || process.env.NPM_CONFIG_NO_PROXY ||
|
|
359
|
+
process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
|
|
344
360
|
|
|
345
361
|
if (!noProxy) {
|
|
346
362
|
return false;
|
|
@@ -135,7 +135,7 @@ function toFormData(obj, formData, options) {
|
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
stack.
|
|
138
|
+
utils.defineOwnProperty(stack, stack.length, value);
|
|
139
139
|
|
|
140
140
|
utils.forEach(value, function each(el) {
|
|
141
141
|
assertValueDepth(el, depth + 1);
|
|
@@ -164,8 +164,8 @@ function toFormData(obj, formData, options) {
|
|
|
164
164
|
value = JSON.stringify(value);
|
|
165
165
|
} else if (
|
|
166
166
|
(utils.isArray(value) && isFlatArray(value)) ||
|
|
167
|
-
(utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
|
|
168
|
-
|
|
167
|
+
((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value)))
|
|
168
|
+
) {
|
|
169
169
|
// eslint-disable-next-line no-param-reassign
|
|
170
170
|
key = removeBrackets(key);
|
|
171
171
|
|
|
@@ -212,7 +212,7 @@ function toFormData(obj, formData, options) {
|
|
|
212
212
|
throw Error('Circular reference detected in ' + path.join('.'));
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
stack.
|
|
215
|
+
utils.defineOwnProperty(stack, stack.length, value);
|
|
216
216
|
|
|
217
217
|
utils.forEach(value, function each(el, key) {
|
|
218
218
|
var result = !(utils.isUndefined(el) || el === null) && visitor.call(
|
package/lib/utils.js
CHANGED
|
@@ -508,10 +508,75 @@ function toArray(thing) {
|
|
|
508
508
|
if (!thing) return null;
|
|
509
509
|
if (isArray(thing)) return thing;
|
|
510
510
|
var i = thing.length;
|
|
511
|
-
if (
|
|
511
|
+
if (typeof i !== 'number' || i < 0 || i > 0xffffffff || Math.floor(i) !== i) return null;
|
|
512
|
+
|
|
513
|
+
// Legacy FileList hosts expose indexed reads without reflecting their keys.
|
|
514
|
+
if (isFileList(thing)) {
|
|
515
|
+
var files = [];
|
|
516
|
+
while (i-- > 0) {
|
|
517
|
+
var file = thing[i];
|
|
518
|
+
if (file === null || isUndefined(file)) return null;
|
|
519
|
+
defineOwnProperty(files, i, file);
|
|
520
|
+
}
|
|
521
|
+
return files;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Count actual indexes, including hidden collection properties, before
|
|
525
|
+
// allocating from the declared length. Box primitives for ES5 object APIs.
|
|
526
|
+
var source = Object(thing);
|
|
527
|
+
var indexes = Object.create(null);
|
|
528
|
+
var count = 0;
|
|
529
|
+
var seen = [];
|
|
530
|
+
var owns = Object.prototype.hasOwnProperty;
|
|
531
|
+
|
|
532
|
+
while (source && count < i) {
|
|
533
|
+
if (seen.indexOf(source) !== -1) return null;
|
|
534
|
+
defineOwnProperty(seen, seen.length, source);
|
|
535
|
+
|
|
536
|
+
if (source === Object.prototype) break;
|
|
537
|
+
|
|
538
|
+
var prototype = Object.getPrototypeOf(source);
|
|
539
|
+
if (prototype === null) {
|
|
540
|
+
var constructorDescriptor = Object.getOwnPropertyDescriptor(source, 'constructor');
|
|
541
|
+
var constructorValue = constructorDescriptor && owns.call(constructorDescriptor, 'value') &&
|
|
542
|
+
constructorDescriptor.value;
|
|
543
|
+
var constructorPrototype = typeof constructorValue === 'function' &&
|
|
544
|
+
Object.getOwnPropertyDescriptor(constructorValue, 'prototype');
|
|
545
|
+
|
|
546
|
+
// Recognize another realm's Object.prototype without excluding
|
|
547
|
+
// application-defined null-prototype parents or invoking accessors.
|
|
548
|
+
if (
|
|
549
|
+
constructorPrototype && owns.call(constructorPrototype, 'value') &&
|
|
550
|
+
constructorPrototype.value === source &&
|
|
551
|
+
Function.prototype.toString.call(constructorValue) === Function.prototype.toString.call(Object)
|
|
552
|
+
) {
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
var keys = Object.getOwnPropertyNames(source);
|
|
558
|
+
for (var j = 0; j < keys.length; j++) {
|
|
559
|
+
var key = keys[j];
|
|
560
|
+
var index = +key;
|
|
561
|
+
if (
|
|
562
|
+
index >= 0 &&
|
|
563
|
+
index < i &&
|
|
564
|
+
Math.floor(index) === index &&
|
|
565
|
+
String(index) === key &&
|
|
566
|
+
owns.call(source, key) &&
|
|
567
|
+
!indexes[key]
|
|
568
|
+
) {
|
|
569
|
+
indexes[key] = true;
|
|
570
|
+
count++;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
source = prototype;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (count !== i) return null;
|
|
512
577
|
var arr = new Array(i);
|
|
513
578
|
while (i-- > 0) {
|
|
514
|
-
arr
|
|
579
|
+
defineOwnProperty(arr, i, thing[i]);
|
|
515
580
|
}
|
|
516
581
|
return arr;
|
|
517
582
|
}
|
|
@@ -581,6 +646,7 @@ module.exports = {
|
|
|
581
646
|
trim: trim,
|
|
582
647
|
stripBOM: stripBOM,
|
|
583
648
|
inherits: inherits,
|
|
649
|
+
defineOwnProperty: defineOwnProperty,
|
|
584
650
|
toFlatObject: toFlatObject,
|
|
585
651
|
kindOf: kindOf,
|
|
586
652
|
kindOfTest: kindOfTest,
|