axios 1.21.0 → 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/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Axios v1.21.0 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);
@@ -427,15 +427,15 @@
427
427
  function _toConsumableArray(r) {
428
428
  return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
429
429
  }
430
- function _toPrimitive(t, r) {
430
+ function _toPrimitive(t, e) {
431
431
  if ("object" != typeof t || !t) return t;
432
- var e = t[Symbol.toPrimitive];
433
- if (void 0 !== e) {
434
- var i = e.call(t, r);
432
+ var r;
433
+ if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) {
434
+ var i = r.call(t, e);
435
435
  if ("object" != typeof i) return i;
436
436
  throw new TypeError("@@toPrimitive must return a primitive value.");
437
437
  }
438
- return ("string" === r ? String : Number)(t);
438
+ return ("string" === e ? String : Number)(t);
439
439
  }
440
440
  function _toPropertyKey(t) {
441
441
  var i = _toPrimitive(t, "string");
@@ -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.0";
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
  *
@@ -5674,18 +5812,34 @@
5674
5812
  }
5675
5813
 
5676
5814
  /**
5677
- * Milliseconds elapsed since `start`, floored at zero.
5815
+ * Resolve the clock used to time adapter execution.
5816
+ *
5817
+ * Prefers the monotonic `performance.now()` so wall-clock adjustments do not
5818
+ * skew the measurement, and so frameworks that forbid reading the current
5819
+ * time during prerendering (e.g. Next.js Cache Components) accept it. Falls
5820
+ * back to `Date.now()` in runtimes without the High Resolution Time API.
5821
+ *
5822
+ * @returns {() => number} Millisecond clock
5823
+ */
5824
+ function resolveClock() {
5825
+ return typeof performance !== 'undefined' && utils$1.isFunction(performance.now) ? function () {
5826
+ return performance.now();
5827
+ } : Date.now;
5828
+ }
5829
+
5830
+ /**
5831
+ * Whole milliseconds elapsed since `start`, floored at zero.
5678
5832
  *
5679
- * Wall-clock, to match the rest of the codebase (speedometer, throttle,
5680
- * AxiosTransformStream). A backwards clock adjustment mid-request would
5681
- * otherwise produce a negative duration, so the result is clamped.
5833
+ * Rounded so the value stays an integer as with `Date.now()`. The fallback
5834
+ * wall clock can move backwards mid-request, so the result is clamped.
5682
5835
  *
5683
- * @param {number} start Timestamp from `Date.now()`
5836
+ * @param {() => number} now Clock returned by `resolveClock()`
5837
+ * @param {number} start Timestamp read from `now`
5684
5838
  *
5685
5839
  * @returns {number} Non-negative elapsed milliseconds
5686
5840
  */
5687
- function elapsedSince(start) {
5688
- return Math.max(0, Date.now() - start);
5841
+ function elapsedSince(now, start) {
5842
+ return Math.max(0, Math.round(now() - start));
5689
5843
  }
5690
5844
 
5691
5845
  /**
@@ -5709,10 +5863,16 @@
5709
5863
  config.headers.setContentType('application/x-www-form-urlencoded', false);
5710
5864
  }
5711
5865
  var adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
5712
- var start = Date.now();
5866
+
5867
+ // Runs after resolution so a custom adapter is recognized in any form.
5868
+ assertValidRequestUrl(config, function () {
5869
+ return adapter;
5870
+ });
5871
+ var now = resolveClock();
5872
+ var start = now();
5713
5873
  return adapter(config).then(function onAdapterResolution(response) {
5714
5874
  throwIfCancellationRequested(config);
5715
- response.duration = elapsedSince(start);
5875
+ response.duration = elapsedSince(now, start);
5716
5876
 
5717
5877
  // Expose the current response on config so that transformResponse can
5718
5878
  // attach it to any AxiosError it throws (e.g. on JSON parse failure).
@@ -5731,7 +5891,7 @@
5731
5891
 
5732
5892
  // Transform response data
5733
5893
  if (reason && reason.response) {
5734
- reason.response.duration = elapsedSince(start);
5894
+ reason.response.duration = elapsedSince(now, start);
5735
5895
  config.response = reason.response;
5736
5896
  try {
5737
5897
  reason.response.data = transformData.call(config, config.transformResponse, reason.response);
@@ -6076,6 +6236,9 @@
6076
6236
  key: "getUri",
6077
6237
  value: function getUri(config) {
6078
6238
  config = mergeConfig(this.defaults, config);
6239
+ assertValidRequestUrl(config, function () {
6240
+ return adapters.getAdapter(config.adapter || defaults.adapter, config);
6241
+ });
6079
6242
  var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
6080
6243
  return buildURL(fullPath, config.params, config.paramsSerializer);
6081
6244
  }