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 +22 -40
- package/dist/axios.js +155 -9
- package/dist/axios.min.js +3 -3
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +179 -7
- package/dist/esm/axios.js +179 -7
- package/dist/esm/axios.min.js +2 -2
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +405 -102
- package/index.d.cts +12 -2
- package/index.d.ts +9 -2
- package/lib/adapters/adapters.js +21 -0
- package/lib/adapters/fetch.js +72 -3
- package/lib/adapters/http.js +181 -41
- package/lib/core/Axios.js +6 -0
- package/lib/core/AxiosHeaders.js +1 -0
- package/lib/core/InterceptorManager.js +7 -2
- package/lib/core/assertValidRequestUrl.js +62 -0
- package/lib/core/dispatchRequest.js +4 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/combineURLs.js +8 -0
- package/lib/helpers/proxyFromEnv.js +158 -0
- package/lib/helpers/shouldBypassProxy.js +2 -1
- package/lib/helpers/trackStream.js +5 -0
- package/package.json +2 -3
package/dist/browser/axios.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Axios v1.
|
|
1
|
+
/*! Axios v1.22.0 Copyright (c) 2026 Matt Zabriskie and contributors */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -1799,6 +1799,7 @@ class AxiosHeaders {
|
|
|
1799
1799
|
AxiosHeaders.accessor([
|
|
1800
1800
|
'Content-Type',
|
|
1801
1801
|
'Content-Length',
|
|
1802
|
+
'Content-Encoding',
|
|
1802
1803
|
'Accept',
|
|
1803
1804
|
'Accept-Encoding',
|
|
1804
1805
|
'User-Agent',
|
|
@@ -2555,8 +2556,13 @@ class InterceptorManager {
|
|
|
2555
2556
|
const handler = {
|
|
2556
2557
|
fulfilled,
|
|
2557
2558
|
rejected,
|
|
2558
|
-
|
|
2559
|
-
|
|
2559
|
+
// Options from a class or template object are read as usual; a value
|
|
2560
|
+
// only inherited from Object.prototype is ignored.
|
|
2561
|
+
synchronous:
|
|
2562
|
+
options && utils$1.hasOwnInPrototypeChain(options, 'synchronous')
|
|
2563
|
+
? options.synchronous
|
|
2564
|
+
: false,
|
|
2565
|
+
runWhen: options && utils$1.hasOwnInPrototypeChain(options, 'runWhen') ? options.runWhen : null,
|
|
2560
2566
|
};
|
|
2561
2567
|
const internals = this[$internals];
|
|
2562
2568
|
|
|
@@ -3453,6 +3459,14 @@ function combineURLs(baseURL, relativeURL) {
|
|
|
3453
3459
|
end--;
|
|
3454
3460
|
}
|
|
3455
3461
|
|
|
3462
|
+
if (end === 0) {
|
|
3463
|
+
// A base made only of slashes points at the root of the current origin.
|
|
3464
|
+
// Drop leading slashes, backslashes, tabs and newlines from the relative
|
|
3465
|
+
// URL as well: URL parsers ignore tabs and newlines and treat '\\' as '/',
|
|
3466
|
+
// so leaving them would turn the result into a protocol-relative URL.
|
|
3467
|
+
return '/' + relativeURL.replace(/^[/\\\t\n\r]+/, '');
|
|
3468
|
+
}
|
|
3469
|
+
|
|
3456
3470
|
return baseURL.slice(0, end) + '/' + relativeURL.replace(/^\/+/, '');
|
|
3457
3471
|
}
|
|
3458
3472
|
|
|
@@ -4449,6 +4463,11 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
4449
4463
|
}
|
|
4450
4464
|
controller.enqueue(new Uint8Array(value));
|
|
4451
4465
|
} catch (err) {
|
|
4466
|
+
// A progress callback can fail while the source iterator is suspended at
|
|
4467
|
+
// a yield. Close it without delaying or replacing the original error.
|
|
4468
|
+
// This return() call has no cancellation reason, so the source's cancel()
|
|
4469
|
+
// receives undefined, as it does from the cancel() hook below.
|
|
4470
|
+
iterator.return().catch(() => {});
|
|
4452
4471
|
_onFinish(err);
|
|
4453
4472
|
throw err;
|
|
4454
4473
|
}
|
|
@@ -4767,7 +4786,7 @@ function estimateDataURLDecodedBytes(url) {
|
|
|
4767
4786
|
);
|
|
4768
4787
|
}
|
|
4769
4788
|
|
|
4770
|
-
const VERSION = "1.
|
|
4789
|
+
const VERSION = "1.22.0";
|
|
4771
4790
|
|
|
4772
4791
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
4773
4792
|
|
|
@@ -4822,6 +4841,45 @@ const test = (fn, ...args) => {
|
|
|
4822
4841
|
}
|
|
4823
4842
|
};
|
|
4824
4843
|
|
|
4844
|
+
// Marks a probe body's cancellation result as handled. Reads `then` once and
|
|
4845
|
+
// does not go through the global Promise or `Promise.prototype.catch`, so a
|
|
4846
|
+
// rejected cancellation from a custom body cannot surface as an unhandled
|
|
4847
|
+
// rejection.
|
|
4848
|
+
const ignoreRejection = (result) => {
|
|
4849
|
+
try {
|
|
4850
|
+
if (result !== null && (typeof result === 'object' || typeof result === 'function')) {
|
|
4851
|
+
const then = result.then;
|
|
4852
|
+
|
|
4853
|
+
if (isFunction(then)) {
|
|
4854
|
+
then.call(result, undefined, utils$1.noop);
|
|
4855
|
+
}
|
|
4856
|
+
}
|
|
4857
|
+
} catch (e) {
|
|
4858
|
+
// Ignored: the cancellation has already been requested.
|
|
4859
|
+
}
|
|
4860
|
+
};
|
|
4861
|
+
|
|
4862
|
+
// On Node.js 22 and older, the body of the throwaway `new Response('')` used by
|
|
4863
|
+
// the response-stream probe leaves its stream's internal closed promise pending
|
|
4864
|
+
// until the stream is cancelled, which async-leak detectors report for every
|
|
4865
|
+
// realm that loads axios. This cleanup runs in `finally`, whether the check
|
|
4866
|
+
// returned or threw, and is best-effort so it never affects the probe result.
|
|
4867
|
+
const cancelProbeBody = (body) => {
|
|
4868
|
+
if (body == null) {
|
|
4869
|
+
return;
|
|
4870
|
+
}
|
|
4871
|
+
|
|
4872
|
+
try {
|
|
4873
|
+
const cancel = body.cancel;
|
|
4874
|
+
|
|
4875
|
+
if (isFunction(cancel)) {
|
|
4876
|
+
ignoreRejection(cancel.call(body));
|
|
4877
|
+
}
|
|
4878
|
+
} catch (e) {
|
|
4879
|
+
// Ignored: an uncancellable probe body is still a valid probe result.
|
|
4880
|
+
}
|
|
4881
|
+
};
|
|
4882
|
+
|
|
4825
4883
|
const maybeWithAuthCredentials = (url) => {
|
|
4826
4884
|
const protocolIndex = url.indexOf('://');
|
|
4827
4885
|
let urlToCheck = url;
|
|
@@ -4887,7 +4945,7 @@ const factory = (env) => {
|
|
|
4887
4945
|
const hasContentType = request.headers.has('Content-Type');
|
|
4888
4946
|
|
|
4889
4947
|
if (request.body != null) {
|
|
4890
|
-
request.body.cancel();
|
|
4948
|
+
ignoreRejection(request.body.cancel());
|
|
4891
4949
|
}
|
|
4892
4950
|
|
|
4893
4951
|
return duplexAccessed && !hasContentType;
|
|
@@ -4896,7 +4954,15 @@ const factory = (env) => {
|
|
|
4896
4954
|
const supportsResponseStream =
|
|
4897
4955
|
isResponseSupported &&
|
|
4898
4956
|
isReadableStreamSupported &&
|
|
4899
|
-
test(() =>
|
|
4957
|
+
test(() => {
|
|
4958
|
+
const probeBody = new Response('').body;
|
|
4959
|
+
|
|
4960
|
+
try {
|
|
4961
|
+
return utils$1.isReadableStream(probeBody);
|
|
4962
|
+
} finally {
|
|
4963
|
+
cancelProbeBody(probeBody);
|
|
4964
|
+
}
|
|
4965
|
+
});
|
|
4900
4966
|
|
|
4901
4967
|
// Some runtimes reject every explicit cache mode. Use own defaults for both
|
|
4902
4968
|
// probes so unrelated polluted options cannot affect cache-mode detection.
|
|
@@ -5468,6 +5534,28 @@ const factory = (env) => {
|
|
|
5468
5534
|
|
|
5469
5535
|
const seedCache = new Map();
|
|
5470
5536
|
|
|
5537
|
+
// Every adapter the factory has created. The adapter is cached per
|
|
5538
|
+
// environment, so one created for another environment, such as by
|
|
5539
|
+
// `axios.getAdapter('fetch')` without a config, is still recognized.
|
|
5540
|
+
const createdAdapters = new WeakSet();
|
|
5541
|
+
|
|
5542
|
+
const createAdapter = (env) => {
|
|
5543
|
+
const adapter = factory(env);
|
|
5544
|
+
|
|
5545
|
+
adapter && createdAdapters.add(adapter);
|
|
5546
|
+
|
|
5547
|
+
return adapter;
|
|
5548
|
+
};
|
|
5549
|
+
|
|
5550
|
+
/**
|
|
5551
|
+
* Check whether a function was created by the fetch adapter factory.
|
|
5552
|
+
*
|
|
5553
|
+
* @param {*} adapter The value to check
|
|
5554
|
+
*
|
|
5555
|
+
* @returns {boolean} `true` for a built-in fetch adapter
|
|
5556
|
+
*/
|
|
5557
|
+
const isFetchAdapter = (adapter) => createdAdapters.has(adapter);
|
|
5558
|
+
|
|
5471
5559
|
const getFetch = (config) => {
|
|
5472
5560
|
const env = Object.create(null);
|
|
5473
5561
|
const configuredEnv = config && utils$1.hasOwnProp(config, 'env') && config.env;
|
|
@@ -5489,7 +5577,7 @@ const getFetch = (config) => {
|
|
|
5489
5577
|
seed = seeds[i];
|
|
5490
5578
|
target = map.get(seed);
|
|
5491
5579
|
|
|
5492
|
-
target === undefined && map.set(seed, (target = i ? new Map() :
|
|
5580
|
+
target === undefined && map.set(seed, (target = i ? new Map() : createAdapter(env)));
|
|
5493
5581
|
|
|
5494
5582
|
map = target;
|
|
5495
5583
|
}
|
|
@@ -5609,6 +5697,21 @@ function getAdapter(adapters, config) {
|
|
|
5609
5697
|
return adapter;
|
|
5610
5698
|
}
|
|
5611
5699
|
|
|
5700
|
+
/**
|
|
5701
|
+
* Check whether a resolved adapter function is one of the built-in adapters.
|
|
5702
|
+
*
|
|
5703
|
+
* @param {Function} adapter The adapter resolved by `getAdapter`
|
|
5704
|
+
* @returns {boolean} `true` for the built-in `xhr`, `http` or `fetch` adapter
|
|
5705
|
+
*/
|
|
5706
|
+
function isBuiltinAdapter(adapter) {
|
|
5707
|
+
return (
|
|
5708
|
+
!!adapter &&
|
|
5709
|
+
(adapter === knownAdapters.xhr ||
|
|
5710
|
+
adapter === knownAdapters.http ||
|
|
5711
|
+
isFetchAdapter(adapter))
|
|
5712
|
+
);
|
|
5713
|
+
}
|
|
5714
|
+
|
|
5612
5715
|
/**
|
|
5613
5716
|
* Exports Axios adapters and utility to resolve an adapter
|
|
5614
5717
|
*/
|
|
@@ -5619,6 +5722,12 @@ var adapters = {
|
|
|
5619
5722
|
*/
|
|
5620
5723
|
getAdapter,
|
|
5621
5724
|
|
|
5725
|
+
/**
|
|
5726
|
+
* Check whether a resolved adapter is a built-in one.
|
|
5727
|
+
* @type {Function}
|
|
5728
|
+
*/
|
|
5729
|
+
isBuiltinAdapter,
|
|
5730
|
+
|
|
5622
5731
|
/**
|
|
5623
5732
|
* Exposes all known adapters
|
|
5624
5733
|
* @type {Object<string, Function|Object>}
|
|
@@ -5626,6 +5735,63 @@ var adapters = {
|
|
|
5626
5735
|
adapters: knownAdapters,
|
|
5627
5736
|
};
|
|
5628
5737
|
|
|
5738
|
+
/**
|
|
5739
|
+
* Reject a `null` or `undefined` url that a built-in adapter would send
|
|
5740
|
+
* somewhere the caller did not choose.
|
|
5741
|
+
*
|
|
5742
|
+
* With params, the nullish url becomes a query-only url such as `?foo=bar`,
|
|
5743
|
+
* which a browser resolves against the current page. Without params, XHR
|
|
5744
|
+
* requests `./null` or `./undefined` and the Node adapter throws a native
|
|
5745
|
+
* `TypeError`.
|
|
5746
|
+
*
|
|
5747
|
+
* The request still has a destination when `baseURL` is set, or when the Node
|
|
5748
|
+
* HTTP adapter is given a `socketPath`. A caller-supplied adapter handles its
|
|
5749
|
+
* own destination and is not checked.
|
|
5750
|
+
*
|
|
5751
|
+
* `dispatchRequest` and `Axios#getUri` both call this, so `getUri` rejects
|
|
5752
|
+
* exactly the configs that a request would reject. Request interceptors are
|
|
5753
|
+
* not run by `getUri`, so a url that an interceptor would supply is still
|
|
5754
|
+
* missing there. Keep this out of `buildURL` and `buildFullPath`: they only
|
|
5755
|
+
* format urls and have other callers.
|
|
5756
|
+
*
|
|
5757
|
+
* @param {Object} config The merged request config
|
|
5758
|
+
* @param {Function} resolveAdapter Returns the adapter that handles the
|
|
5759
|
+
* request. Called only for a nullish url without `baseURL`, so a usable url
|
|
5760
|
+
* never depends on adapter resolution.
|
|
5761
|
+
*
|
|
5762
|
+
* @returns {void}
|
|
5763
|
+
*/
|
|
5764
|
+
function assertValidRequestUrl(config, resolveAdapter) {
|
|
5765
|
+
const url = utils$1.getSafeProp(config, 'url');
|
|
5766
|
+
|
|
5767
|
+
if (url !== null && url !== undefined) {
|
|
5768
|
+
return;
|
|
5769
|
+
}
|
|
5770
|
+
|
|
5771
|
+
if (utils$1.getSafeProp(config, 'baseURL')) {
|
|
5772
|
+
return;
|
|
5773
|
+
}
|
|
5774
|
+
|
|
5775
|
+
const adapter = resolveAdapter();
|
|
5776
|
+
|
|
5777
|
+
// Only the Node HTTP adapter reads socketPath; XHR and fetch ignore it.
|
|
5778
|
+
const httpAdapter = adapters.adapters.http;
|
|
5779
|
+
|
|
5780
|
+
if (httpAdapter && adapter === httpAdapter && utils$1.getSafeProp(config, 'socketPath')) {
|
|
5781
|
+
return;
|
|
5782
|
+
}
|
|
5783
|
+
|
|
5784
|
+
if (!adapters.isBuiltinAdapter(adapter)) {
|
|
5785
|
+
return;
|
|
5786
|
+
}
|
|
5787
|
+
|
|
5788
|
+
throw new AxiosError(
|
|
5789
|
+
`Invalid URL: url cannot be ${url === null ? 'null' : 'undefined'} when baseURL is not set`,
|
|
5790
|
+
AxiosError.ERR_INVALID_URL,
|
|
5791
|
+
config
|
|
5792
|
+
);
|
|
5793
|
+
}
|
|
5794
|
+
|
|
5629
5795
|
/**
|
|
5630
5796
|
* Throws a `CanceledError` if cancellation has been requested.
|
|
5631
5797
|
*
|
|
@@ -5700,6 +5866,9 @@ function dispatchRequest(_config) {
|
|
|
5700
5866
|
|
|
5701
5867
|
const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
|
|
5702
5868
|
|
|
5869
|
+
// Runs after resolution so a custom adapter is recognized in any form.
|
|
5870
|
+
assertValidRequestUrl(config, () => adapter);
|
|
5871
|
+
|
|
5703
5872
|
const now = resolveClock();
|
|
5704
5873
|
const start = now();
|
|
5705
5874
|
|
|
@@ -6155,6 +6324,9 @@ class Axios {
|
|
|
6155
6324
|
|
|
6156
6325
|
getUri(config) {
|
|
6157
6326
|
config = mergeConfig(this.defaults, config);
|
|
6327
|
+
assertValidRequestUrl(config, () =>
|
|
6328
|
+
adapters.getAdapter(config.adapter || defaults.adapter, config)
|
|
6329
|
+
);
|
|
6158
6330
|
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
|
|
6159
6331
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
6160
6332
|
}
|
package/dist/esm/axios.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Axios v1.
|
|
1
|
+
/*! Axios v1.22.0 Copyright (c) 2026 Matt Zabriskie and contributors */
|
|
2
2
|
/**
|
|
3
3
|
* Create a bound version of a function with a specified `this` context
|
|
4
4
|
*
|
|
@@ -1797,6 +1797,7 @@ let AxiosHeaders$1 = class AxiosHeaders {
|
|
|
1797
1797
|
AxiosHeaders$1.accessor([
|
|
1798
1798
|
'Content-Type',
|
|
1799
1799
|
'Content-Length',
|
|
1800
|
+
'Content-Encoding',
|
|
1800
1801
|
'Accept',
|
|
1801
1802
|
'Accept-Encoding',
|
|
1802
1803
|
'User-Agent',
|
|
@@ -2553,8 +2554,13 @@ class InterceptorManager {
|
|
|
2553
2554
|
const handler = {
|
|
2554
2555
|
fulfilled,
|
|
2555
2556
|
rejected,
|
|
2556
|
-
|
|
2557
|
-
|
|
2557
|
+
// Options from a class or template object are read as usual; a value
|
|
2558
|
+
// only inherited from Object.prototype is ignored.
|
|
2559
|
+
synchronous:
|
|
2560
|
+
options && utils$1.hasOwnInPrototypeChain(options, 'synchronous')
|
|
2561
|
+
? options.synchronous
|
|
2562
|
+
: false,
|
|
2563
|
+
runWhen: options && utils$1.hasOwnInPrototypeChain(options, 'runWhen') ? options.runWhen : null,
|
|
2558
2564
|
};
|
|
2559
2565
|
const internals = this[$internals];
|
|
2560
2566
|
|
|
@@ -3451,6 +3457,14 @@ function combineURLs(baseURL, relativeURL) {
|
|
|
3451
3457
|
end--;
|
|
3452
3458
|
}
|
|
3453
3459
|
|
|
3460
|
+
if (end === 0) {
|
|
3461
|
+
// A base made only of slashes points at the root of the current origin.
|
|
3462
|
+
// Drop leading slashes, backslashes, tabs and newlines from the relative
|
|
3463
|
+
// URL as well: URL parsers ignore tabs and newlines and treat '\\' as '/',
|
|
3464
|
+
// so leaving them would turn the result into a protocol-relative URL.
|
|
3465
|
+
return '/' + relativeURL.replace(/^[/\\\t\n\r]+/, '');
|
|
3466
|
+
}
|
|
3467
|
+
|
|
3454
3468
|
return baseURL.slice(0, end) + '/' + relativeURL.replace(/^\/+/, '');
|
|
3455
3469
|
}
|
|
3456
3470
|
|
|
@@ -4447,6 +4461,11 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
4447
4461
|
}
|
|
4448
4462
|
controller.enqueue(new Uint8Array(value));
|
|
4449
4463
|
} catch (err) {
|
|
4464
|
+
// A progress callback can fail while the source iterator is suspended at
|
|
4465
|
+
// a yield. Close it without delaying or replacing the original error.
|
|
4466
|
+
// This return() call has no cancellation reason, so the source's cancel()
|
|
4467
|
+
// receives undefined, as it does from the cancel() hook below.
|
|
4468
|
+
iterator.return().catch(() => {});
|
|
4450
4469
|
_onFinish(err);
|
|
4451
4470
|
throw err;
|
|
4452
4471
|
}
|
|
@@ -4765,7 +4784,7 @@ function estimateDataURLDecodedBytes(url) {
|
|
|
4765
4784
|
);
|
|
4766
4785
|
}
|
|
4767
4786
|
|
|
4768
|
-
const VERSION$1 = "1.
|
|
4787
|
+
const VERSION$1 = "1.22.0";
|
|
4769
4788
|
|
|
4770
4789
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
4771
4790
|
|
|
@@ -4820,6 +4839,45 @@ const test = (fn, ...args) => {
|
|
|
4820
4839
|
}
|
|
4821
4840
|
};
|
|
4822
4841
|
|
|
4842
|
+
// Marks a probe body's cancellation result as handled. Reads `then` once and
|
|
4843
|
+
// does not go through the global Promise or `Promise.prototype.catch`, so a
|
|
4844
|
+
// rejected cancellation from a custom body cannot surface as an unhandled
|
|
4845
|
+
// rejection.
|
|
4846
|
+
const ignoreRejection = (result) => {
|
|
4847
|
+
try {
|
|
4848
|
+
if (result !== null && (typeof result === 'object' || typeof result === 'function')) {
|
|
4849
|
+
const then = result.then;
|
|
4850
|
+
|
|
4851
|
+
if (isFunction(then)) {
|
|
4852
|
+
then.call(result, undefined, utils$1.noop);
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4855
|
+
} catch (e) {
|
|
4856
|
+
// Ignored: the cancellation has already been requested.
|
|
4857
|
+
}
|
|
4858
|
+
};
|
|
4859
|
+
|
|
4860
|
+
// On Node.js 22 and older, the body of the throwaway `new Response('')` used by
|
|
4861
|
+
// the response-stream probe leaves its stream's internal closed promise pending
|
|
4862
|
+
// until the stream is cancelled, which async-leak detectors report for every
|
|
4863
|
+
// realm that loads axios. This cleanup runs in `finally`, whether the check
|
|
4864
|
+
// returned or threw, and is best-effort so it never affects the probe result.
|
|
4865
|
+
const cancelProbeBody = (body) => {
|
|
4866
|
+
if (body == null) {
|
|
4867
|
+
return;
|
|
4868
|
+
}
|
|
4869
|
+
|
|
4870
|
+
try {
|
|
4871
|
+
const cancel = body.cancel;
|
|
4872
|
+
|
|
4873
|
+
if (isFunction(cancel)) {
|
|
4874
|
+
ignoreRejection(cancel.call(body));
|
|
4875
|
+
}
|
|
4876
|
+
} catch (e) {
|
|
4877
|
+
// Ignored: an uncancellable probe body is still a valid probe result.
|
|
4878
|
+
}
|
|
4879
|
+
};
|
|
4880
|
+
|
|
4823
4881
|
const maybeWithAuthCredentials = (url) => {
|
|
4824
4882
|
const protocolIndex = url.indexOf('://');
|
|
4825
4883
|
let urlToCheck = url;
|
|
@@ -4885,7 +4943,7 @@ const factory = (env) => {
|
|
|
4885
4943
|
const hasContentType = request.headers.has('Content-Type');
|
|
4886
4944
|
|
|
4887
4945
|
if (request.body != null) {
|
|
4888
|
-
request.body.cancel();
|
|
4946
|
+
ignoreRejection(request.body.cancel());
|
|
4889
4947
|
}
|
|
4890
4948
|
|
|
4891
4949
|
return duplexAccessed && !hasContentType;
|
|
@@ -4894,7 +4952,15 @@ const factory = (env) => {
|
|
|
4894
4952
|
const supportsResponseStream =
|
|
4895
4953
|
isResponseSupported &&
|
|
4896
4954
|
isReadableStreamSupported &&
|
|
4897
|
-
test(() =>
|
|
4955
|
+
test(() => {
|
|
4956
|
+
const probeBody = new Response('').body;
|
|
4957
|
+
|
|
4958
|
+
try {
|
|
4959
|
+
return utils$1.isReadableStream(probeBody);
|
|
4960
|
+
} finally {
|
|
4961
|
+
cancelProbeBody(probeBody);
|
|
4962
|
+
}
|
|
4963
|
+
});
|
|
4898
4964
|
|
|
4899
4965
|
// Some runtimes reject every explicit cache mode. Use own defaults for both
|
|
4900
4966
|
// probes so unrelated polluted options cannot affect cache-mode detection.
|
|
@@ -5466,6 +5532,28 @@ const factory = (env) => {
|
|
|
5466
5532
|
|
|
5467
5533
|
const seedCache = new Map();
|
|
5468
5534
|
|
|
5535
|
+
// Every adapter the factory has created. The adapter is cached per
|
|
5536
|
+
// environment, so one created for another environment, such as by
|
|
5537
|
+
// `axios.getAdapter('fetch')` without a config, is still recognized.
|
|
5538
|
+
const createdAdapters = new WeakSet();
|
|
5539
|
+
|
|
5540
|
+
const createAdapter = (env) => {
|
|
5541
|
+
const adapter = factory(env);
|
|
5542
|
+
|
|
5543
|
+
adapter && createdAdapters.add(adapter);
|
|
5544
|
+
|
|
5545
|
+
return adapter;
|
|
5546
|
+
};
|
|
5547
|
+
|
|
5548
|
+
/**
|
|
5549
|
+
* Check whether a function was created by the fetch adapter factory.
|
|
5550
|
+
*
|
|
5551
|
+
* @param {*} adapter The value to check
|
|
5552
|
+
*
|
|
5553
|
+
* @returns {boolean} `true` for a built-in fetch adapter
|
|
5554
|
+
*/
|
|
5555
|
+
const isFetchAdapter = (adapter) => createdAdapters.has(adapter);
|
|
5556
|
+
|
|
5469
5557
|
const getFetch = (config) => {
|
|
5470
5558
|
const env = Object.create(null);
|
|
5471
5559
|
const configuredEnv = config && utils$1.hasOwnProp(config, 'env') && config.env;
|
|
@@ -5487,7 +5575,7 @@ const getFetch = (config) => {
|
|
|
5487
5575
|
seed = seeds[i];
|
|
5488
5576
|
target = map.get(seed);
|
|
5489
5577
|
|
|
5490
|
-
target === undefined && map.set(seed, (target = i ? new Map() :
|
|
5578
|
+
target === undefined && map.set(seed, (target = i ? new Map() : createAdapter(env)));
|
|
5491
5579
|
|
|
5492
5580
|
map = target;
|
|
5493
5581
|
}
|
|
@@ -5607,6 +5695,21 @@ function getAdapter$1(adapters, config) {
|
|
|
5607
5695
|
return adapter;
|
|
5608
5696
|
}
|
|
5609
5697
|
|
|
5698
|
+
/**
|
|
5699
|
+
* Check whether a resolved adapter function is one of the built-in adapters.
|
|
5700
|
+
*
|
|
5701
|
+
* @param {Function} adapter The adapter resolved by `getAdapter`
|
|
5702
|
+
* @returns {boolean} `true` for the built-in `xhr`, `http` or `fetch` adapter
|
|
5703
|
+
*/
|
|
5704
|
+
function isBuiltinAdapter(adapter) {
|
|
5705
|
+
return (
|
|
5706
|
+
!!adapter &&
|
|
5707
|
+
(adapter === knownAdapters.xhr ||
|
|
5708
|
+
adapter === knownAdapters.http ||
|
|
5709
|
+
isFetchAdapter(adapter))
|
|
5710
|
+
);
|
|
5711
|
+
}
|
|
5712
|
+
|
|
5610
5713
|
/**
|
|
5611
5714
|
* Exports Axios adapters and utility to resolve an adapter
|
|
5612
5715
|
*/
|
|
@@ -5617,6 +5720,12 @@ var adapters = {
|
|
|
5617
5720
|
*/
|
|
5618
5721
|
getAdapter: getAdapter$1,
|
|
5619
5722
|
|
|
5723
|
+
/**
|
|
5724
|
+
* Check whether a resolved adapter is a built-in one.
|
|
5725
|
+
* @type {Function}
|
|
5726
|
+
*/
|
|
5727
|
+
isBuiltinAdapter,
|
|
5728
|
+
|
|
5620
5729
|
/**
|
|
5621
5730
|
* Exposes all known adapters
|
|
5622
5731
|
* @type {Object<string, Function|Object>}
|
|
@@ -5624,6 +5733,63 @@ var adapters = {
|
|
|
5624
5733
|
adapters: knownAdapters,
|
|
5625
5734
|
};
|
|
5626
5735
|
|
|
5736
|
+
/**
|
|
5737
|
+
* Reject a `null` or `undefined` url that a built-in adapter would send
|
|
5738
|
+
* somewhere the caller did not choose.
|
|
5739
|
+
*
|
|
5740
|
+
* With params, the nullish url becomes a query-only url such as `?foo=bar`,
|
|
5741
|
+
* which a browser resolves against the current page. Without params, XHR
|
|
5742
|
+
* requests `./null` or `./undefined` and the Node adapter throws a native
|
|
5743
|
+
* `TypeError`.
|
|
5744
|
+
*
|
|
5745
|
+
* The request still has a destination when `baseURL` is set, or when the Node
|
|
5746
|
+
* HTTP adapter is given a `socketPath`. A caller-supplied adapter handles its
|
|
5747
|
+
* own destination and is not checked.
|
|
5748
|
+
*
|
|
5749
|
+
* `dispatchRequest` and `Axios#getUri` both call this, so `getUri` rejects
|
|
5750
|
+
* exactly the configs that a request would reject. Request interceptors are
|
|
5751
|
+
* not run by `getUri`, so a url that an interceptor would supply is still
|
|
5752
|
+
* missing there. Keep this out of `buildURL` and `buildFullPath`: they only
|
|
5753
|
+
* format urls and have other callers.
|
|
5754
|
+
*
|
|
5755
|
+
* @param {Object} config The merged request config
|
|
5756
|
+
* @param {Function} resolveAdapter Returns the adapter that handles the
|
|
5757
|
+
* request. Called only for a nullish url without `baseURL`, so a usable url
|
|
5758
|
+
* never depends on adapter resolution.
|
|
5759
|
+
*
|
|
5760
|
+
* @returns {void}
|
|
5761
|
+
*/
|
|
5762
|
+
function assertValidRequestUrl(config, resolveAdapter) {
|
|
5763
|
+
const url = utils$1.getSafeProp(config, 'url');
|
|
5764
|
+
|
|
5765
|
+
if (url !== null && url !== undefined) {
|
|
5766
|
+
return;
|
|
5767
|
+
}
|
|
5768
|
+
|
|
5769
|
+
if (utils$1.getSafeProp(config, 'baseURL')) {
|
|
5770
|
+
return;
|
|
5771
|
+
}
|
|
5772
|
+
|
|
5773
|
+
const adapter = resolveAdapter();
|
|
5774
|
+
|
|
5775
|
+
// Only the Node HTTP adapter reads socketPath; XHR and fetch ignore it.
|
|
5776
|
+
const httpAdapter = adapters.adapters.http;
|
|
5777
|
+
|
|
5778
|
+
if (httpAdapter && adapter === httpAdapter && utils$1.getSafeProp(config, 'socketPath')) {
|
|
5779
|
+
return;
|
|
5780
|
+
}
|
|
5781
|
+
|
|
5782
|
+
if (!adapters.isBuiltinAdapter(adapter)) {
|
|
5783
|
+
return;
|
|
5784
|
+
}
|
|
5785
|
+
|
|
5786
|
+
throw new AxiosError$1(
|
|
5787
|
+
`Invalid URL: url cannot be ${url === null ? 'null' : 'undefined'} when baseURL is not set`,
|
|
5788
|
+
AxiosError$1.ERR_INVALID_URL,
|
|
5789
|
+
config
|
|
5790
|
+
);
|
|
5791
|
+
}
|
|
5792
|
+
|
|
5627
5793
|
/**
|
|
5628
5794
|
* Throws a `CanceledError` if cancellation has been requested.
|
|
5629
5795
|
*
|
|
@@ -5698,6 +5864,9 @@ function dispatchRequest(_config) {
|
|
|
5698
5864
|
|
|
5699
5865
|
const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
|
|
5700
5866
|
|
|
5867
|
+
// Runs after resolution so a custom adapter is recognized in any form.
|
|
5868
|
+
assertValidRequestUrl(config, () => adapter);
|
|
5869
|
+
|
|
5701
5870
|
const now = resolveClock();
|
|
5702
5871
|
const start = now();
|
|
5703
5872
|
|
|
@@ -6153,6 +6322,9 @@ let Axios$1 = class Axios {
|
|
|
6153
6322
|
|
|
6154
6323
|
getUri(config) {
|
|
6155
6324
|
config = mergeConfig$1(this.defaults, config);
|
|
6325
|
+
assertValidRequestUrl(config, () =>
|
|
6326
|
+
adapters.getAdapter(config.adapter || defaults.adapter, config)
|
|
6327
|
+
);
|
|
6156
6328
|
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls, config);
|
|
6157
6329
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
6158
6330
|
}
|