axios 1.7.4 → 1.7.6
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.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +30 -0
- package/README.md +7 -57
- package/dist/axios.js +94 -68
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +76 -57
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +76 -57
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +77 -58
- package/dist/node/axios.cjs.map +1 -1
- package/lib/adapters/fetch.js +18 -18
- package/lib/adapters/http.js +1 -1
- package/lib/cancel/CancelToken.js +14 -0
- package/lib/core/AxiosError.js +5 -2
- package/lib/env/data.js +1 -1
- package/lib/helpers/composeSignals.js +31 -29
- package/lib/helpers/isURLSameOrigin.js +1 -1
- package/lib/platform/common/utils.js +5 -4
- package/package.json +1 -1
package/dist/node/axios.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// Axios v1.7.
|
1
|
+
// Axios v1.7.6 Copyright (c) 2024 Matt Zabriskie and contributors
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
const FormData$1 = require('form-data');
|
@@ -811,7 +811,10 @@ function AxiosError(message, code, config, request, response) {
|
|
811
811
|
code && (this.code = code);
|
812
812
|
config && (this.config = config);
|
813
813
|
request && (this.request = request);
|
814
|
-
|
814
|
+
if (response) {
|
815
|
+
this.response = response;
|
816
|
+
this.status = response.status ? response.status : null;
|
817
|
+
}
|
815
818
|
}
|
816
819
|
|
817
820
|
utils$1.inherits(AxiosError, Error, {
|
@@ -831,7 +834,7 @@ utils$1.inherits(AxiosError, Error, {
|
|
831
834
|
// Axios
|
832
835
|
config: utils$1.toJSONObject(this.config),
|
833
836
|
code: this.code,
|
834
|
-
status: this.
|
837
|
+
status: this.status
|
835
838
|
};
|
836
839
|
}
|
837
840
|
});
|
@@ -1292,6 +1295,8 @@ const platform$1 = {
|
|
1292
1295
|
|
1293
1296
|
const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
|
1294
1297
|
|
1298
|
+
const _navigator = typeof navigator === 'object' && navigator || undefined;
|
1299
|
+
|
1295
1300
|
/**
|
1296
1301
|
* Determine if we're running in a standard browser environment
|
1297
1302
|
*
|
@@ -1309,10 +1314,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
|
|
1309
1314
|
*
|
1310
1315
|
* @returns {boolean}
|
1311
1316
|
*/
|
1312
|
-
const hasStandardBrowserEnv =
|
1313
|
-
(product)
|
1314
|
-
return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
|
1315
|
-
})(typeof navigator !== 'undefined' && navigator.product);
|
1317
|
+
const hasStandardBrowserEnv = hasBrowserEnv &&
|
1318
|
+
(!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
|
1316
1319
|
|
1317
1320
|
/**
|
1318
1321
|
* Determine if we're running in a standard browser webWorker environment
|
@@ -1339,6 +1342,7 @@ const utils = /*#__PURE__*/Object.freeze({
|
|
1339
1342
|
hasBrowserEnv: hasBrowserEnv,
|
1340
1343
|
hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
|
1341
1344
|
hasStandardBrowserEnv: hasStandardBrowserEnv,
|
1345
|
+
navigator: _navigator,
|
1342
1346
|
origin: origin
|
1343
1347
|
});
|
1344
1348
|
|
@@ -2067,7 +2071,7 @@ function buildFullPath(baseURL, requestedURL) {
|
|
2067
2071
|
return requestedURL;
|
2068
2072
|
}
|
2069
2073
|
|
2070
|
-
const VERSION = "1.7.
|
2074
|
+
const VERSION = "1.7.6";
|
2071
2075
|
|
2072
2076
|
function parseProtocol(url) {
|
2073
2077
|
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
@@ -2763,7 +2767,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
2763
2767
|
|
2764
2768
|
// Parse url
|
2765
2769
|
const fullPath = buildFullPath(config.baseURL, config.url);
|
2766
|
-
const parsed = new URL(fullPath,
|
2770
|
+
const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
|
2767
2771
|
const protocol = parsed.protocol || supportedProtocols[0];
|
2768
2772
|
|
2769
2773
|
if (protocol === 'data:') {
|
@@ -3229,7 +3233,7 @@ const isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
|
3229
3233
|
// Standard browser envs have full support of the APIs needed to test
|
3230
3234
|
// whether the request URL is of the same origin as current location.
|
3231
3235
|
(function standardBrowserEnv() {
|
3232
|
-
const msie = /(msie|trident)/i.test(navigator.userAgent);
|
3236
|
+
const msie = platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent);
|
3233
3237
|
const urlParsingNode = document.createElement('a');
|
3234
3238
|
let originURL;
|
3235
3239
|
|
@@ -3664,45 +3668,46 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
3664
3668
|
};
|
3665
3669
|
|
3666
3670
|
const composeSignals = (signals, timeout) => {
|
3667
|
-
|
3671
|
+
const {length} = (signals = signals ? signals.filter(Boolean) : []);
|
3668
3672
|
|
3669
|
-
|
3673
|
+
if (timeout || length) {
|
3674
|
+
let controller = new AbortController();
|
3670
3675
|
|
3671
|
-
|
3672
|
-
if (!aborted) {
|
3673
|
-
aborted = true;
|
3674
|
-
unsubscribe();
|
3675
|
-
const err = cancel instanceof Error ? cancel : this.reason;
|
3676
|
-
controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
|
3677
|
-
}
|
3678
|
-
};
|
3676
|
+
let aborted;
|
3679
3677
|
|
3680
|
-
|
3681
|
-
|
3682
|
-
|
3678
|
+
const onabort = function (reason) {
|
3679
|
+
if (!aborted) {
|
3680
|
+
aborted = true;
|
3681
|
+
unsubscribe();
|
3682
|
+
const err = reason instanceof Error ? reason : this.reason;
|
3683
|
+
controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
|
3684
|
+
}
|
3685
|
+
};
|
3683
3686
|
|
3684
|
-
|
3685
|
-
if (signals) {
|
3686
|
-
timer && clearTimeout(timer);
|
3687
|
+
let timer = timeout && setTimeout(() => {
|
3687
3688
|
timer = null;
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
3691
|
-
|
3692
|
-
signals
|
3693
|
-
|
3694
|
-
|
3689
|
+
onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
|
3690
|
+
}, timeout);
|
3691
|
+
|
3692
|
+
const unsubscribe = () => {
|
3693
|
+
if (signals) {
|
3694
|
+
timer && clearTimeout(timer);
|
3695
|
+
timer = null;
|
3696
|
+
signals.forEach(signal => {
|
3697
|
+
signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
|
3698
|
+
});
|
3699
|
+
signals = null;
|
3700
|
+
}
|
3701
|
+
};
|
3695
3702
|
|
3696
|
-
|
3703
|
+
signals.forEach((signal) => signal.addEventListener('abort', onabort));
|
3697
3704
|
|
3698
|
-
|
3705
|
+
const {signal} = controller;
|
3699
3706
|
|
3700
|
-
|
3707
|
+
signal.unsubscribe = () => utils$1.asap(unsubscribe);
|
3701
3708
|
|
3702
|
-
|
3703
|
-
|
3704
|
-
timer = null;
|
3705
|
-
}];
|
3709
|
+
return signal;
|
3710
|
+
}
|
3706
3711
|
};
|
3707
3712
|
|
3708
3713
|
const composeSignals$1 = composeSignals;
|
@@ -3835,7 +3840,11 @@ const getBodyLength = async (body) => {
|
|
3835
3840
|
}
|
3836
3841
|
|
3837
3842
|
if(utils$1.isSpecCompliantForm(body)) {
|
3838
|
-
|
3843
|
+
const _request = new Request(platform.origin, {
|
3844
|
+
method: 'POST',
|
3845
|
+
body,
|
3846
|
+
});
|
3847
|
+
return (await _request.arrayBuffer()).byteLength;
|
3839
3848
|
}
|
3840
3849
|
|
3841
3850
|
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
@@ -3875,18 +3884,13 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
3875
3884
|
|
3876
3885
|
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
3877
3886
|
|
3878
|
-
let
|
3879
|
-
composeSignals$1([signal, cancelToken], timeout) : [];
|
3880
|
-
|
3881
|
-
let finished, request;
|
3887
|
+
let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
3882
3888
|
|
3883
|
-
|
3884
|
-
!finished && setTimeout(() => {
|
3885
|
-
composedSignal && composedSignal.unsubscribe();
|
3886
|
-
});
|
3889
|
+
let request;
|
3887
3890
|
|
3888
|
-
|
3889
|
-
|
3891
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
3892
|
+
composedSignal.unsubscribe();
|
3893
|
+
});
|
3890
3894
|
|
3891
3895
|
let requestContentLength;
|
3892
3896
|
|
@@ -3921,6 +3925,9 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
3921
3925
|
withCredentials = withCredentials ? 'include' : 'omit';
|
3922
3926
|
}
|
3923
3927
|
|
3928
|
+
// Cloudflare Workers throws when credentials are defined
|
3929
|
+
// see https://github.com/cloudflare/workerd/issues/902
|
3930
|
+
const isCredentialsSupported = "credentials" in Request.prototype;
|
3924
3931
|
request = new Request(url, {
|
3925
3932
|
...fetchOptions,
|
3926
3933
|
signal: composedSignal,
|
@@ -3928,14 +3935,14 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
3928
3935
|
headers: headers.normalize().toJSON(),
|
3929
3936
|
body: data,
|
3930
3937
|
duplex: "half",
|
3931
|
-
credentials: withCredentials
|
3938
|
+
credentials: isCredentialsSupported ? withCredentials : undefined
|
3932
3939
|
});
|
3933
3940
|
|
3934
3941
|
let response = await fetch(request);
|
3935
3942
|
|
3936
3943
|
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
3937
3944
|
|
3938
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
|
3945
|
+
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
3939
3946
|
const options = {};
|
3940
3947
|
|
3941
3948
|
['status', 'statusText', 'headers'].forEach(prop => {
|
@@ -3952,7 +3959,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
3952
3959
|
response = new Response(
|
3953
3960
|
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
3954
3961
|
flush && flush();
|
3955
|
-
|
3962
|
+
unsubscribe && unsubscribe();
|
3956
3963
|
}, encodeText),
|
3957
3964
|
options
|
3958
3965
|
);
|
@@ -3962,9 +3969,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
3962
3969
|
|
3963
3970
|
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
3964
3971
|
|
3965
|
-
!isStreamResponse &&
|
3966
|
-
|
3967
|
-
stopTimeout && stopTimeout();
|
3972
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
3968
3973
|
|
3969
3974
|
return await new Promise((resolve, reject) => {
|
3970
3975
|
settle(resolve, reject, {
|
@@ -3977,7 +3982,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
3977
3982
|
});
|
3978
3983
|
})
|
3979
3984
|
} catch (err) {
|
3980
|
-
|
3985
|
+
unsubscribe && unsubscribe();
|
3981
3986
|
|
3982
3987
|
if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
|
3983
3988
|
throw Object.assign(
|
@@ -4544,6 +4549,20 @@ class CancelToken {
|
|
4544
4549
|
}
|
4545
4550
|
}
|
4546
4551
|
|
4552
|
+
toAbortSignal() {
|
4553
|
+
const controller = new AbortController();
|
4554
|
+
|
4555
|
+
const abort = (err) => {
|
4556
|
+
controller.abort(err);
|
4557
|
+
};
|
4558
|
+
|
4559
|
+
this.subscribe(abort);
|
4560
|
+
|
4561
|
+
controller.signal.unsubscribe = () => this.unsubscribe(abort);
|
4562
|
+
|
4563
|
+
return controller.signal;
|
4564
|
+
}
|
4565
|
+
|
4547
4566
|
/**
|
4548
4567
|
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
4549
4568
|
* cancels the `CancelToken`.
|