axios 1.21.1 → 1.22.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,158 @@
1
+ 'use strict';
2
+
3
+ // Resolves the proxy for a URL from the standard proxy environment variables.
4
+ // Adapted from proxy-from-env 2.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. The port of a parsed URL
7
+ // is also read as a decimal number.
8
+ //
9
+ // proxy-from-env is distributed under the MIT License:
10
+ //
11
+ // Copyright (C) 2016-2018 Rob Wu <rob@robwu.nl>
12
+ //
13
+ // Permission is hereby granted, free of charge, to any person obtaining a copy of
14
+ // this software and associated documentation files (the "Software"), to deal in
15
+ // the Software without restriction, including without limitation the rights to
16
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
+ // of the Software, and to permit persons to whom the Software is furnished to do
18
+ // so, subject to the following conditions:
19
+ //
20
+ // The above copyright notice and this permission notice shall be included in all
21
+ // copies or substantial portions of the Software.
22
+ //
23
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25
+ // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
26
+ // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
27
+ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28
+ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+
30
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
31
+
32
+ const DEFAULT_PORTS = {
33
+ ftp: 21,
34
+ gopher: 70,
35
+ http: 80,
36
+ https: 443,
37
+ ws: 80,
38
+ wss: 443,
39
+ };
40
+
41
+ function parseUrl(urlString) {
42
+ try {
43
+ return new URL(urlString);
44
+ } catch (err) {
45
+ return null;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Read one environment variable without trusting Object.prototype.
51
+ *
52
+ * A name that is not set on process.env itself is ignored when Object.prototype
53
+ * has a property of the same name. Any other name is read as usual, so an env
54
+ * object that a test runner replaces or wraps keeps working.
55
+ *
56
+ * @param {string} name The exact name of the environment variable.
57
+ * @returns {string|undefined} The value, or undefined when it must not be used.
58
+ */
59
+ function readEnv(name) {
60
+ const env = process.env;
61
+
62
+ if (name in Object.prototype && !hasOwnProperty.call(env, name)) {
63
+ return undefined;
64
+ }
65
+
66
+ return env[name];
67
+ }
68
+
69
+ /**
70
+ * Get the value of an environment variable, preferring the lower-case name.
71
+ *
72
+ * @param {string} key The name of the environment variable.
73
+ * @returns {string} The value, or an empty string when it is not set.
74
+ */
75
+ export function getEnv(key) {
76
+ return readEnv(key.toLowerCase()) || readEnv(key.toUpperCase()) || '';
77
+ }
78
+
79
+ /**
80
+ * Determine whether a request to the given host and port should be proxied,
81
+ * according to no_proxy.
82
+ *
83
+ * @param {string} hostname The host of the URL, with IPv6 brackets kept.
84
+ * @param {number} port The effective port of the URL.
85
+ * @returns {boolean} Whether the request should be proxied.
86
+ */
87
+ function shouldProxy(hostname, port) {
88
+ const noProxy = getEnv('no_proxy').toLowerCase();
89
+
90
+ if (!noProxy) {
91
+ return true;
92
+ }
93
+
94
+ if (noProxy === '*') {
95
+ return false;
96
+ }
97
+
98
+ return noProxy.split(/[,\s]/).every((entry) => {
99
+ if (!entry) {
100
+ return true;
101
+ }
102
+
103
+ const parsedEntry = entry.match(/^(.+):(\d+)$/);
104
+ let entryHostname = parsedEntry ? parsedEntry[1] : entry;
105
+ const entryPort = parsedEntry ? parseInt(parsedEntry[2], 10) : 0;
106
+
107
+ if (entryPort && entryPort !== port) {
108
+ return true;
109
+ }
110
+
111
+ if (!/^[.*]/.test(entryHostname)) {
112
+ return hostname !== entryHostname;
113
+ }
114
+
115
+ if (entryHostname.charAt(0) === '*') {
116
+ entryHostname = entryHostname.slice(1);
117
+ }
118
+
119
+ return !hostname.endsWith(entryHostname);
120
+ });
121
+ }
122
+
123
+ /**
124
+ * Get the proxy URL that should handle a request to the given URL.
125
+ *
126
+ * @param {string|URL|Object} url The request URL, a URL instance, or a
127
+ * compatible object such as the result of url.parse.
128
+ * @returns {string} The proxy URL, or an empty string when no proxy applies.
129
+ */
130
+ export function getProxyForUrl(url) {
131
+ const parsedUrl = (typeof url === 'string' ? parseUrl(url) : url) || {};
132
+ let proto = parsedUrl.protocol;
133
+ let hostname = parsedUrl.host;
134
+ let port = parsedUrl.port;
135
+
136
+ if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
137
+ return '';
138
+ }
139
+
140
+ proto = proto.split(':', 1)[0];
141
+ // Strip the port this way rather than using parsedUrl.hostname so the
142
+ // brackets around IPv6 addresses are kept.
143
+ hostname = hostname.replace(/:\d*$/, '');
144
+ port = parseInt(port, 10) || DEFAULT_PORTS[proto] || 0;
145
+
146
+ if (!shouldProxy(hostname, port)) {
147
+ return '';
148
+ }
149
+
150
+ let proxy = getEnv(proto + '_proxy') || getEnv('all_proxy');
151
+
152
+ if (proxy && proxy.indexOf('://') === -1) {
153
+ // No scheme in the proxy value: default to the request URL's scheme.
154
+ proxy = proto + '://' + proxy;
155
+ }
156
+
157
+ return proxy;
158
+ }
@@ -1,4 +1,5 @@
1
1
  import { domainToASCII } from 'url';
2
+ import { getEnv } from './proxyFromEnv.js';
2
3
 
3
4
  const LOOPBACK_HOSTNAMES = new Set(['localhost', '0.0.0.0']);
4
5
 
@@ -459,7 +460,7 @@ export default function shouldBypassProxy(location) {
459
460
  return false;
460
461
  }
461
462
 
462
- const noProxy = (process.env.no_proxy || process.env.NO_PROXY || '').toLowerCase();
463
+ const noProxy = getEnv('no_proxy').toLowerCase();
463
464
 
464
465
  if (!noProxy) {
465
466
  return false;
@@ -73,6 +73,11 @@ export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
73
73
  }
74
74
  controller.enqueue(new Uint8Array(value));
75
75
  } catch (err) {
76
+ // A progress callback can fail while the source iterator is suspended at
77
+ // a yield. Close it without delaying or replacing the original error.
78
+ // This return() call has no cancellation reason, so the source's cancel()
79
+ // receives undefined, as it does from the cancel() hook below.
80
+ iterator.return().catch(() => {});
76
81
  _onFinish(err);
77
82
  throw err;
78
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.21.1",
3
+ "version": "1.22.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "./dist/node/axios.cjs",
6
6
  "module": "./index.js",
@@ -141,8 +141,7 @@
141
141
  "dependencies": {
142
142
  "follow-redirects": "^1.16.2",
143
143
  "form-data": "^4.0.6",
144
- "https-proxy-agent": "^5.0.1",
145
- "proxy-from-env": "^2.1.0"
144
+ "https-proxy-agent": "^5.0.1"
146
145
  },
147
146
  "devDependencies": {
148
147
  "@babel/core": "^7.29.7",