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.
package/README.md CHANGED
@@ -86,33 +86,6 @@
86
86
  >
87
87
  </p>
88
88
  </td>
89
- <td align="center" width="33.333333333333336%">
90
- <a
91
- href="https://opensource.sap.com?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship"
92
- style="padding: 10px; display: inline-block"
93
- target="_blank"
94
- >
95
- <img
96
- width="90px"
97
- height="90px"
98
- src="https://avatars.githubusercontent.com/u/2531208?s=200&v=4"
99
- alt="SAP"
100
- />
101
- </a>
102
- <p
103
- align="center"
104
- title="SAP SE, a global software company, is one of the largest vendors of ERP and other enterprise applications."
105
- >
106
- SAP SE, a global software company, is one of the largest vendors of ERP and other enterprise applications.
107
- </p>
108
- <p align="center">
109
- <a
110
- href="https://opensource.sap.com?utm_source&#x3D;axios&amp;utm_medium&#x3D;readme_sponsorlist&amp;utm_campaign&#x3D;sponsorship"
111
- target="_blank"
112
- ><b>opensource.sap.com</b></a
113
- >
114
- </p>
115
- </td>
116
89
  <td align="center" width="33.333333333333336%">
117
90
  <a
118
91
  href="https://www.descope.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;referral&amp;utm_campaign&#x3D;axios-oss-sponsorship"
@@ -140,8 +113,6 @@
140
113
  >
141
114
  </p>
142
115
  </td>
143
- </tr>
144
- <tr width="33.333333333333336%">
145
116
  <td align="center" width="33.333333333333336%">
146
117
  <a
147
118
  href="https://rxdb.info/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship&utm_content=logo"
@@ -168,6 +139,8 @@
168
139
  >
169
140
  </p>
170
141
  </td>
142
+ </tr>
143
+ <tr width="33.333333333333336%">
171
144
  <td align="center" width="33.333333333333336%">
172
145
  <a
173
146
  href="https://poprey.com/?utm_source&#x3D;axios&amp;utm_medium&#x3D;sponsorlist&amp;utm_campaign&#x3D;sponsorship"
@@ -218,8 +191,6 @@
218
191
  >
219
192
  </p>
220
193
  </td>
221
- </tr>
222
- <tr width="33.333333333333336%">
223
194
  <td align="center" width="33.333333333333336%">
224
195
  <a
225
196
  href="https://www.jbo88b.com/vn/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
@@ -246,6 +217,8 @@
246
217
  >
247
218
  </p>
248
219
  </td>
220
+ </tr>
221
+ <tr width="33.333333333333336%">
249
222
  <td align="center" width="33.333333333333336%">
250
223
  <a
251
224
  href="https://www.jbo579.com/th/?utm_source=axios_docs_website&utm_medium=website&utm_campaign=axios_open_collective_sponsorship"
@@ -298,8 +271,6 @@
298
271
  >
299
272
  </p>
300
273
  </td>
301
- </tr>
302
- <tr width="33.333333333333336%">
303
274
  <td align="center" width="33.333333333333336%">
304
275
  <a
305
276
  href="https://www.herodevs.com/support/nes-for-axios?utm_source=axios-site&amp;utm_medium=referral&amp;utm_campaign=nes-for-axios_global&amp;utm_content=landing-page_none_20260924_a"
@@ -326,6 +297,8 @@
326
297
  >
327
298
  </p>
328
299
  </td>
300
+ </tr>
301
+ <tr width="33.333333333333336%">
329
302
  <td align="center" width="33.333333333333336%">
330
303
  <a
331
304
  href="https://opencollective.com/sweepico-promo-code"
@@ -515,6 +488,12 @@ Using Deno:
515
488
  $ deno add axios
516
489
  ```
517
490
 
491
+ Using vlt:
492
+
493
+ ```bash
494
+ $ vlt install axios
495
+ ```
496
+
518
497
  Once the package is installed, import it with `import` or `require`:
519
498
 
520
499
  ```js
@@ -1141,7 +1120,7 @@ These config options are available for requests. Only `url` is required. Request
1141
1120
  // try to parse the response string as JSON even if `responseType` is not 'json'
1142
1121
  forcedJSONParsing: true,
1143
1122
 
1144
- // throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
1123
+ // Set to true to use ETIMEDOUT for timeouts in the http and xhr adapters.
1145
1124
  clarifyTimeoutError: false,
1146
1125
 
1147
1126
  // keep explicit `validateStatus: undefined` resolving every response status
@@ -1519,11 +1498,11 @@ These are the internal Axios error codes:
1519
1498
  | ERR_NOT_SUPPORT | Feature or method not supported in the current axios environment. |
1520
1499
  | ERR_DEPRECATED | Deprecated feature or method used in axios. |
1521
1500
  | ERR_INVALID_URL | Invalid URL provided for axios request. |
1522
- | ECONNABORTED | Typically indicates that the request has been timed out (unless `transitional.clarifyTimeoutError` is set) or aborted by the browser or its plugin. |
1501
+ | ECONNABORTED | The `http` and `xhr` adapters use this code for timeouts by default. The `xhr` adapter can also use it when the browser aborts a request. |
1523
1502
  | ERR_CANCELED | The user explicitly canceled the request with an AbortSignal or CancelToken. |
1524
- | ETIMEDOUT | Request timed out after exceeding the configured Axios timeout. Set `transitional.clarifyTimeoutError` to `true`; otherwise Axios throws a generic `ECONNABORTED` error. |
1503
+ | ETIMEDOUT | For Axios timeout errors, the `fetch` adapter uses this code regardless of `transitional.clarifyTimeoutError`. The `http` and `xhr` adapters use it when that option is `true`. |
1525
1504
  | ECONNREFUSED | The server refused the connection. Set by the Node.js `http` adapter, with the original system error on `error.cause`; the `xhr` and `fetch` adapters report `ERR_NETWORK` instead. |
1526
- | ERR_NETWORK | Network-related issue. In the browser, this error can also be caused by a [CORS](https://developer.mozilla.org/ru/docs/Web/HTTP/Guides/CORS) or [Mixed Content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content) policy violation. The browser does not allow the JS code to clarify the real reason for the error caused by security issues, so please check the console. |
1505
+ | ERR_NETWORK | Network-related issue. In the browser, this error can also be caused by a [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) or [Mixed Content](https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content) policy violation. The browser does not allow the JS code to clarify the real reason for the error caused by security issues, so please check the console. |
1527
1506
  | ERR_FR_TOO_MANY_REDIRECTS | Request exceeded the configured maximum number of redirects. |
1528
1507
  | ERR_BAD_RESPONSE | Response cannot be parsed properly or is in an unexpected format. Usually related to a response with `5xx` status code. |
1529
1508
  | ERR_BAD_REQUEST | The request has an unexpected format or is missing required parameters. Usually related to a response with `4xx` status code. |
@@ -1604,13 +1583,15 @@ axios
1604
1583
 
1605
1584
  ## Handling timeouts
1606
1585
 
1586
+ For Axios timeout errors, the `http` and `xhr` adapters reject with `ECONNABORTED` by default. Set `transitional.clarifyTimeoutError: true` to get `ETIMEDOUT` from those adapters. The `fetch` adapter uses `ETIMEDOUT` regardless of this setting.
1587
+
1607
1588
  ```js
1608
1589
  async function fetchWithTimeout() {
1609
1590
  try {
1610
1591
  const response = await axios.get('https://example.com/data', {
1611
1592
  timeout: 5000, // 5 seconds
1612
1593
  transitional: {
1613
- // set to true if you prefer ETIMEDOUT over ECONNABORTED
1594
+ // Set to true to use ETIMEDOUT for timeouts in the http and xhr adapters.
1614
1595
  clarifyTimeoutError: false,
1615
1596
  },
1616
1597
  });
@@ -2520,8 +2501,9 @@ const fetchAxios = axios.create({
2520
2501
  const { data } = fetchAxios.get(url);
2521
2502
  ```
2522
2503
 
2523
- The adapter supports the same features as the `xhr` adapter, including upload and download progress capturing.
2524
- It also supports response types such as `stream` and `formdata` when the environment supports them.
2504
+ Upload progress requires request stream support and is reported only for methods other than `GET` and `HEAD` with a non-empty request body.
2505
+ Download progress requires response stream support and a readable response body.
2506
+ The adapter also supports response types such as `stream` and `formdata` when the environment supports them.
2525
2507
 
2526
2508
  When `auth` is omitted, the fetch adapter can read HTTP Basic auth credentials from the request URL, for example `https://user:pass@example.com`. Percent-encoded URL credentials are decoded before the `Authorization` header is generated, and `auth` takes precedence over URL-embedded credentials.
2527
2509
 
package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Axios v1.21.1 Copyright (c) 2026 Matt Zabriskie and contributors */
1
+ /*! Axios v1.22.0 Copyright (c) 2026 Matt Zabriskie and contributors */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -84,7 +84,7 @@
84
84
  }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
85
85
  },
86
86
  throw: function (r) {
87
- var n = this.s.return;
87
+ var n = this.s.throw;
88
88
  return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
89
89
  }
90
90
  }, new AsyncFromSyncIterator(r);
@@ -2166,7 +2166,7 @@
2166
2166
  }
2167
2167
  }]);
2168
2168
  }();
2169
- AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
2169
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Content-Encoding', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
2170
2170
 
2171
2171
  // reserved names hotfix
2172
2172
  utils$1.reduceDescriptors(AxiosHeaders.prototype, function (_ref3, key) {
@@ -2825,8 +2825,10 @@
2825
2825
  var handler = {
2826
2826
  fulfilled: fulfilled,
2827
2827
  rejected: rejected,
2828
- synchronous: options ? options.synchronous : false,
2829
- runWhen: options ? options.runWhen : null
2828
+ // Options from a class or template object are read as usual; a value
2829
+ // only inherited from Object.prototype is ignored.
2830
+ synchronous: options && utils$1.hasOwnInPrototypeChain(options, 'synchronous') ? options.synchronous : false,
2831
+ runWhen: options && utils$1.hasOwnInPrototypeChain(options, 'runWhen') ? options.runWhen : null
2830
2832
  };
2831
2833
  var internals = this[$internals];
2832
2834
  if (this.handlers == null) {
@@ -3626,6 +3628,13 @@
3626
3628
  while (end > 0 && baseURL.charCodeAt(end - 1) === 47) {
3627
3629
  end--;
3628
3630
  }
3631
+ if (end === 0) {
3632
+ // A base made only of slashes points at the root of the current origin.
3633
+ // Drop leading slashes, backslashes, tabs and newlines from the relative
3634
+ // URL as well: URL parsers ignore tabs and newlines and treat '\\' as '/',
3635
+ // so leaving them would turn the result into a protocol-relative URL.
3636
+ return '/' + relativeURL.replace(/^[/\\\t\n\r]+/, '');
3637
+ }
3629
3638
  return baseURL.slice(0, end) + '/' + relativeURL.replace(/^\/+/, '');
3630
3639
  }
3631
3640
 
@@ -4614,6 +4623,11 @@
4614
4623
  case 3:
4615
4624
  _context4.p = 3;
4616
4625
  _t2 = _context4.v;
4626
+ // A progress callback can fail while the source iterator is suspended at
4627
+ // a yield. Close it without delaying or replacing the original error.
4628
+ // This return() call has no cancellation reason, so the source's cancel()
4629
+ // receives undefined, as it does from the cancel() hook below.
4630
+ iterator["return"]()["catch"](function () {});
4617
4631
  _onFinish(_t2);
4618
4632
  throw _t2;
4619
4633
  case 4:
@@ -4910,7 +4924,7 @@
4910
4924
  return estimateDataURLBytes(fragmentIndex === -1 ? url : url.slice(0, fragmentIndex), estimatePercentDecodedBase64Bytes, /; *base64[\t\n\f\r ]*$/i);
4911
4925
  }
4912
4926
 
4913
- var VERSION = "1.21.1";
4927
+ var VERSION = "1.22.0";
4914
4928
 
4915
4929
  var DEFAULT_CHUNK_SIZE = 64 * 1024;
4916
4930
  var DEFAULT_REQUEST_OPTIONS = {
@@ -4964,6 +4978,42 @@
4964
4978
  return false;
4965
4979
  }
4966
4980
  };
4981
+
4982
+ // Marks a probe body's cancellation result as handled. Reads `then` once and
4983
+ // does not go through the global Promise or `Promise.prototype.catch`, so a
4984
+ // rejected cancellation from a custom body cannot surface as an unhandled
4985
+ // rejection.
4986
+ var ignoreRejection = function ignoreRejection(result) {
4987
+ try {
4988
+ if (result !== null && (_typeof(result) === 'object' || typeof result === 'function')) {
4989
+ var then = result.then;
4990
+ if (isFunction(then)) {
4991
+ then.call(result, undefined, utils$1.noop);
4992
+ }
4993
+ }
4994
+ } catch (e) {
4995
+ // Ignored: the cancellation has already been requested.
4996
+ }
4997
+ };
4998
+
4999
+ // On Node.js 22 and older, the body of the throwaway `new Response('')` used by
5000
+ // the response-stream probe leaves its stream's internal closed promise pending
5001
+ // until the stream is cancelled, which async-leak detectors report for every
5002
+ // realm that loads axios. This cleanup runs in `finally`, whether the check
5003
+ // returned or threw, and is best-effort so it never affects the probe result.
5004
+ var cancelProbeBody = function cancelProbeBody(body) {
5005
+ if (body == null) {
5006
+ return;
5007
+ }
5008
+ try {
5009
+ var cancel = body.cancel;
5010
+ if (isFunction(cancel)) {
5011
+ ignoreRejection(cancel.call(body));
5012
+ }
5013
+ } catch (e) {
5014
+ // Ignored: an uncancellable probe body is still a valid probe result.
5015
+ }
5016
+ };
4967
5017
  var maybeWithAuthCredentials = function maybeWithAuthCredentials(url) {
4968
5018
  var protocolIndex = url.indexOf('://');
4969
5019
  var urlToCheck = url;
@@ -5030,12 +5080,17 @@
5030
5080
  });
5031
5081
  var hasContentType = request.headers.has('Content-Type');
5032
5082
  if (request.body != null) {
5033
- request.body.cancel();
5083
+ ignoreRejection(request.body.cancel());
5034
5084
  }
5035
5085
  return duplexAccessed && !hasContentType;
5036
5086
  });
5037
5087
  var supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(function () {
5038
- return utils$1.isReadableStream(new Response('').body);
5088
+ var probeBody = new Response('').body;
5089
+ try {
5090
+ return utils$1.isReadableStream(probeBody);
5091
+ } finally {
5092
+ cancelProbeBody(probeBody);
5093
+ }
5039
5094
  });
5040
5095
 
5041
5096
  // Some runtimes reject every explicit cache mode. Use own defaults for both
@@ -5511,6 +5566,27 @@
5511
5566
  }();
5512
5567
  };
5513
5568
  var seedCache = new Map();
5569
+
5570
+ // Every adapter the factory has created. The adapter is cached per
5571
+ // environment, so one created for another environment, such as by
5572
+ // `axios.getAdapter('fetch')` without a config, is still recognized.
5573
+ var createdAdapters = new WeakSet();
5574
+ var createAdapter = function createAdapter(env) {
5575
+ var adapter = factory(env);
5576
+ adapter && createdAdapters.add(adapter);
5577
+ return adapter;
5578
+ };
5579
+
5580
+ /**
5581
+ * Check whether a function was created by the fetch adapter factory.
5582
+ *
5583
+ * @param {*} adapter The value to check
5584
+ *
5585
+ * @returns {boolean} `true` for a built-in fetch adapter
5586
+ */
5587
+ var isFetchAdapter = function isFetchAdapter(adapter) {
5588
+ return createdAdapters.has(adapter);
5589
+ };
5514
5590
  var getFetch = function getFetch(config) {
5515
5591
  var env = Object.create(null);
5516
5592
  var configuredEnv = config && utils$1.hasOwnProp(config, 'env') && config.env;
@@ -5532,7 +5608,7 @@
5532
5608
  while (i--) {
5533
5609
  seed = seeds[i];
5534
5610
  target = map.get(seed);
5535
- target === undefined && map.set(seed, target = i ? new Map() : factory(env));
5611
+ target === undefined && map.set(seed, target = i ? new Map() : createAdapter(env));
5536
5612
  map = target;
5537
5613
  }
5538
5614
  return target;
@@ -5641,6 +5717,16 @@
5641
5717
  return adapter;
5642
5718
  }
5643
5719
 
5720
+ /**
5721
+ * Check whether a resolved adapter function is one of the built-in adapters.
5722
+ *
5723
+ * @param {Function} adapter The adapter resolved by `getAdapter`
5724
+ * @returns {boolean} `true` for the built-in `xhr`, `http` or `fetch` adapter
5725
+ */
5726
+ function isBuiltinAdapter(adapter) {
5727
+ return !!adapter && (adapter === knownAdapters.xhr || adapter === knownAdapters.http || isFetchAdapter(adapter));
5728
+ }
5729
+
5644
5730
  /**
5645
5731
  * Exports Axios adapters and utility to resolve an adapter
5646
5732
  */
@@ -5650,6 +5736,11 @@
5650
5736
  * @type {Function}
5651
5737
  */
5652
5738
  getAdapter: getAdapter,
5739
+ /**
5740
+ * Check whether a resolved adapter is a built-in one.
5741
+ * @type {Function}
5742
+ */
5743
+ isBuiltinAdapter: isBuiltinAdapter,
5653
5744
  /**
5654
5745
  * Exposes all known adapters
5655
5746
  * @type {Object<string, Function|Object>}
@@ -5657,6 +5748,53 @@
5657
5748
  adapters: knownAdapters
5658
5749
  };
5659
5750
 
5751
+ /**
5752
+ * Reject a `null` or `undefined` url that a built-in adapter would send
5753
+ * somewhere the caller did not choose.
5754
+ *
5755
+ * With params, the nullish url becomes a query-only url such as `?foo=bar`,
5756
+ * which a browser resolves against the current page. Without params, XHR
5757
+ * requests `./null` or `./undefined` and the Node adapter throws a native
5758
+ * `TypeError`.
5759
+ *
5760
+ * The request still has a destination when `baseURL` is set, or when the Node
5761
+ * HTTP adapter is given a `socketPath`. A caller-supplied adapter handles its
5762
+ * own destination and is not checked.
5763
+ *
5764
+ * `dispatchRequest` and `Axios#getUri` both call this, so `getUri` rejects
5765
+ * exactly the configs that a request would reject. Request interceptors are
5766
+ * not run by `getUri`, so a url that an interceptor would supply is still
5767
+ * missing there. Keep this out of `buildURL` and `buildFullPath`: they only
5768
+ * format urls and have other callers.
5769
+ *
5770
+ * @param {Object} config The merged request config
5771
+ * @param {Function} resolveAdapter Returns the adapter that handles the
5772
+ * request. Called only for a nullish url without `baseURL`, so a usable url
5773
+ * never depends on adapter resolution.
5774
+ *
5775
+ * @returns {void}
5776
+ */
5777
+ function assertValidRequestUrl(config, resolveAdapter) {
5778
+ var url = utils$1.getSafeProp(config, 'url');
5779
+ if (url !== null && url !== undefined) {
5780
+ return;
5781
+ }
5782
+ if (utils$1.getSafeProp(config, 'baseURL')) {
5783
+ return;
5784
+ }
5785
+ var adapter = resolveAdapter();
5786
+
5787
+ // Only the Node HTTP adapter reads socketPath; XHR and fetch ignore it.
5788
+ var httpAdapter = adapters.adapters.http;
5789
+ if (httpAdapter && adapter === httpAdapter && utils$1.getSafeProp(config, 'socketPath')) {
5790
+ return;
5791
+ }
5792
+ if (!adapters.isBuiltinAdapter(adapter)) {
5793
+ return;
5794
+ }
5795
+ throw new AxiosError("Invalid URL: url cannot be ".concat(url === null ? 'null' : 'undefined', " when baseURL is not set"), AxiosError.ERR_INVALID_URL, config);
5796
+ }
5797
+
5660
5798
  /**
5661
5799
  * Throws a `CanceledError` if cancellation has been requested.
5662
5800
  *
@@ -5725,6 +5863,11 @@
5725
5863
  config.headers.setContentType('application/x-www-form-urlencoded', false);
5726
5864
  }
5727
5865
  var adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
5866
+
5867
+ // Runs after resolution so a custom adapter is recognized in any form.
5868
+ assertValidRequestUrl(config, function () {
5869
+ return adapter;
5870
+ });
5728
5871
  var now = resolveClock();
5729
5872
  var start = now();
5730
5873
  return adapter(config).then(function onAdapterResolution(response) {
@@ -6093,6 +6236,9 @@
6093
6236
  key: "getUri",
6094
6237
  value: function getUri(config) {
6095
6238
  config = mergeConfig(this.defaults, config);
6239
+ assertValidRequestUrl(config, function () {
6240
+ return adapters.getAdapter(config.adapter || defaults.adapter, config);
6241
+ });
6096
6242
  var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
6097
6243
  return buildURL(fullPath, config.params, config.paramsSerializer);
6098
6244
  }