axios 0.34.0 → 0.36.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.
@@ -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
+ };
@@ -0,0 +1,152 @@
1
+ 'use strict';
2
+
3
+ // Resolves the proxy for a URL from the standard proxy environment variables.
4
+ // Adapted from proxy-from-env 1.1.0 (https://github.com/Rob--W/proxy-from-env).
5
+ // A variable that is not set on process.env itself is ignored when
6
+ // Object.prototype has a property of the same name, so a polluted prototype
7
+ // cannot choose the proxy or skip it. The port of a parsed URL object is also
8
+ // read as a decimal number, which matches every port url.parse produces.
9
+ //
10
+ // proxy-from-env is distributed under the MIT License:
11
+ //
12
+ // Copyright (C) 2016-2018 Rob Wu <rob@robwu.nl>
13
+ //
14
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of
15
+ // this software and associated documentation files (the "Software"), to deal in
16
+ // the Software without restriction, including without limitation the rights to
17
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
+ // of the Software, and to permit persons to whom the Software is furnished to do
19
+ // so, subject to the following conditions:
20
+ //
21
+ // The above copyright notice and this permission notice shall be included in all
22
+ // copies or substantial portions of the Software.
23
+ //
24
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
26
+ // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
27
+ // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
28
+ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
+ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
+
31
+ var parseUrl = require('url').parse;
32
+ var utils = require('./../utils');
33
+
34
+ var DEFAULT_PORTS = {
35
+ ftp: 21,
36
+ gopher: 70,
37
+ http: 80,
38
+ https: 443,
39
+ ws: 80,
40
+ wss: 443
41
+ };
42
+
43
+ /**
44
+ * Read one environment variable without trusting Object.prototype.
45
+ *
46
+ * A name that is not set on process.env itself is ignored when Object.prototype
47
+ * has a property of the same name. Any other name is read as usual, so an env
48
+ * object that a test runner replaces or wraps keeps working.
49
+ *
50
+ * @param {string} name The exact name of the environment variable.
51
+ * @returns {string|undefined} The value, or undefined when it must not be used.
52
+ */
53
+ function readEnv(name) {
54
+ var env = process.env;
55
+
56
+ if (utils.hasOwnProperty(env, name) || !(name in Object.prototype)) {
57
+ return env[name];
58
+ }
59
+
60
+ return undefined;
61
+ }
62
+
63
+ /**
64
+ * Get the value of an environment variable, preferring the lower-case name.
65
+ *
66
+ * @param {string} key The name of the environment variable.
67
+ * @returns {string} The value, or an empty string when it is not set.
68
+ */
69
+ function getEnv(key) {
70
+ return readEnv(key.toLowerCase()) || readEnv(key.toUpperCase()) || '';
71
+ }
72
+
73
+ function shouldProxy(hostname, port) {
74
+ var noProxy = (getEnv('npm_config_no_proxy') || getEnv('no_proxy')).toLowerCase();
75
+
76
+ if (!noProxy) {
77
+ return true;
78
+ }
79
+
80
+ if (noProxy === '*') {
81
+ return false;
82
+ }
83
+
84
+ return noProxy.split(/[,\s]/).every(function testEntry(entry) {
85
+ if (!entry) {
86
+ return true;
87
+ }
88
+
89
+ var parsedEntry = entry.match(/^(.+):(\d+)$/);
90
+ var entryHostname = parsedEntry ? parsedEntry[1] : entry;
91
+ var entryPort = parsedEntry ? parseInt(parsedEntry[2], 10) : 0;
92
+
93
+ if (entryPort && entryPort !== port) {
94
+ return true;
95
+ }
96
+
97
+ if (!/^[.*]/.test(entryHostname)) {
98
+ return hostname !== entryHostname;
99
+ }
100
+
101
+ if (entryHostname.charAt(0) === '*') {
102
+ entryHostname = entryHostname.slice(1);
103
+ }
104
+
105
+ return !utils.endsWith(hostname, entryHostname);
106
+ });
107
+ }
108
+
109
+ /**
110
+ * Get the proxy URL that should handle a request to the given URL.
111
+ *
112
+ * @param {string|Object} location The request URL, or the result of url.parse.
113
+ * @returns {string} The proxy URL, or an empty string when no proxy applies.
114
+ */
115
+ function getProxyForUrl(location) {
116
+ var parsedUrl = typeof location === 'string' ? parseUrl(location) : location || {};
117
+ var proto = parsedUrl.protocol;
118
+ var hostname = parsedUrl.host;
119
+ var port = parsedUrl.port;
120
+
121
+ if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
122
+ return '';
123
+ }
124
+
125
+ proto = proto.split(':', 1)[0];
126
+ // Strip the port this way rather than using parsedUrl.hostname so the
127
+ // brackets around IPv6 addresses are kept.
128
+ hostname = hostname.replace(/:\d*$/, '');
129
+ port = parseInt(port, 10) || DEFAULT_PORTS[proto] || 0;
130
+
131
+ if (!shouldProxy(hostname, port)) {
132
+ return '';
133
+ }
134
+
135
+ var proxy =
136
+ getEnv('npm_config_' + proto + '_proxy') ||
137
+ getEnv(proto + '_proxy') ||
138
+ getEnv('npm_config_proxy') ||
139
+ getEnv('all_proxy');
140
+
141
+ if (proxy && proxy.indexOf('://') === -1) {
142
+ // No scheme in the proxy value: default to the request URL's scheme.
143
+ proxy = proto + '://' + proxy;
144
+ }
145
+
146
+ return proxy;
147
+ }
148
+
149
+ module.exports = {
150
+ getProxyForUrl: getProxyForUrl,
151
+ getEnv: getEnv
152
+ };
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var URL = require('url').URL;
4
+ var domainToASCII = require('url').domainToASCII;
5
+ var getEnv = require('./proxyFromEnv').getEnv;
4
6
 
5
7
  var DEFAULT_PORTS = {
6
8
  http: 80,
@@ -130,6 +132,20 @@ function normalizeNoProxyHost(hostname) {
130
132
 
131
133
  hostname = stripTrailingDots(hostname);
132
134
 
135
+ if (hostname.indexOf(':') !== -1) {
136
+ try {
137
+ hostname = new URL('http://[' + hostname + ']/').hostname.slice(1, -1);
138
+ } catch (err) {
139
+ return hostname;
140
+ }
141
+ } else if (/[\u0080-\uffff]/.test(hostname)) {
142
+ var prefix = /^[*.]+/.exec(hostname);
143
+ var start = prefix ? prefix[0] : '';
144
+ var ascii = domainToASCII(hostname.slice(start.length));
145
+ if (!ascii) return '';
146
+ hostname = start + stripTrailingDots(ascii);
147
+ }
148
+
133
149
  return normalizeIPv4MappedIPv6(hostname);
134
150
  }
135
151
 
@@ -340,7 +356,7 @@ module.exports = function shouldBypassProxy(location) {
340
356
  return false;
341
357
  }
342
358
 
343
- var noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
359
+ var noProxy = (getEnv('npm_config_no_proxy') || getEnv('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.push(value);
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.push(value);
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 (!isNumber(i)) return null;
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[i] = thing[i];
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "0.34.0",
3
+ "version": "0.36.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",
@@ -36,47 +36,47 @@
36
36
  "@rollup/plugin-json": "^4.1.0",
37
37
  "@rollup/plugin-multi-entry": "^4.0.0",
38
38
  "@rollup/plugin-node-resolve": "^9.0.0",
39
- "abortcontroller-polyfill": "^1.7.3",
40
- "body-parser": "^1.20.0",
39
+ "abortcontroller-polyfill": "^1.7.8",
40
+ "body-parser": "^1.20.9",
41
41
  "coveralls": "^3.1.1",
42
42
  "cross-env": "^7.0.3",
43
43
  "dtslint": "4.2.1",
44
44
  "es6-promise": "^4.2.8",
45
- "express": "^4.18.1",
46
- "formidable": "^2.0.1",
47
- "grunt": "^1.4.1",
45
+ "express": "^4.22.3",
46
+ "formidable": "2.1.2",
47
+ "grunt": "~1.5.3",
48
48
  "grunt-banner": "^0.6.0",
49
- "grunt-cli": "^1.4.3",
49
+ "grunt-cli": "^1.5.0",
50
50
  "grunt-contrib-clean": "^2.0.0",
51
51
  "grunt-contrib-watch": "^1.1.0",
52
- "grunt-eslint": "^24.0.0",
52
+ "grunt-eslint": "^24.3.0",
53
53
  "grunt-karma": "^4.0.2",
54
54
  "grunt-mocha-test": "^0.13.3",
55
55
  "grunt-shell": "^3.0.1",
56
56
  "grunt-webpack": "^5.0.0",
57
57
  "istanbul-instrumenter-loader": "^3.0.1",
58
58
  "jasmine-core": "^2.4.1",
59
- "karma": "^6.3.17",
60
- "karma-chrome-launcher": "^3.1.1",
59
+ "karma": "^6.4.4",
60
+ "karma-chrome-launcher": "^3.2.0",
61
61
  "karma-firefox-launcher": "^2.1.2",
62
62
  "karma-jasmine": "^1.1.1",
63
63
  "karma-jasmine-ajax": "^0.1.13",
64
64
  "karma-safari-launcher": "^1.0.0",
65
65
  "karma-sauce-launcher": "^4.3.6",
66
66
  "karma-sinon": "^1.0.5",
67
- "karma-sourcemap-loader": "^0.3.8",
67
+ "karma-sourcemap-loader": "^0.4.0",
68
68
  "karma-webpack": "^4.0.2",
69
69
  "load-grunt-tasks": "^5.1.0",
70
- "minimist": "^1.2.6",
70
+ "minimist": "^1.2.8",
71
71
  "mocha": "^8.2.1",
72
72
  "multer": "^1.4.4",
73
- "rollup": "^2.67.0",
73
+ "rollup": "^2.80.0",
74
74
  "rollup-plugin-terser": "^7.0.2",
75
75
  "sinon": "^4.5.0",
76
76
  "terser-webpack-plugin": "^4.2.3",
77
- "typescript": "^4.6.3",
77
+ "typescript": "^4.9.5",
78
78
  "url-search-params": "^0.10.0",
79
- "webpack": "^4.44.2",
79
+ "webpack": "^4.47.0",
80
80
  "webpack-dev-server": "^3.11.0"
81
81
  },
82
82
  "browser": {
@@ -87,9 +87,8 @@
87
87
  "unpkg": "dist/axios.min.js",
88
88
  "typings": "./index.d.ts",
89
89
  "dependencies": {
90
- "follow-redirects": "^1.15.4",
91
- "form-data": "^4.0.4",
92
- "proxy-from-env": "^1.1.0"
90
+ "follow-redirects": "^1.16.2",
91
+ "form-data": "^4.0.6"
93
92
  },
94
93
  "bundlesize": [
95
94
  {