axios 1.4.0 → 1.6.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.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +204 -0
- package/README.md +301 -12
- package/dist/axios.js +58 -29
- 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 +65 -38
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +67 -39
- 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 +93 -51
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +20 -11
- package/index.d.ts +23 -12
- package/index.js +2 -0
- package/lib/adapters/adapters.js +33 -15
- package/lib/adapters/http.js +28 -13
- package/lib/adapters/xhr.js +9 -4
- package/lib/axios.js +3 -0
- package/lib/core/Axios.js +2 -4
- package/lib/core/AxiosHeaders.js +11 -1
- package/lib/defaults/index.js +3 -10
- package/lib/env/data.js +1 -1
- package/lib/utils.js +3 -2
- package/package.json +3 -1
package/dist/node/axios.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// Axios v1.
|
1
|
+
// Axios v1.6.0 Copyright (c) 2023 Matt Zabriskie and contributors
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
const FormData$1 = require('form-data');
|
@@ -568,8 +568,9 @@ const reduceDescriptors = (obj, reducer) => {
|
|
568
568
|
const reducedDescriptors = {};
|
569
569
|
|
570
570
|
forEach(descriptors, (descriptor, name) => {
|
571
|
-
|
572
|
-
|
571
|
+
let ret;
|
572
|
+
if ((ret = reducer(descriptor, name, obj)) !== false) {
|
573
|
+
reducedDescriptors[name] = ret || descriptor;
|
573
574
|
}
|
574
575
|
});
|
575
576
|
|
@@ -1353,10 +1354,6 @@ function formDataToJSON(formData) {
|
|
1353
1354
|
return null;
|
1354
1355
|
}
|
1355
1356
|
|
1356
|
-
const DEFAULT_CONTENT_TYPE = {
|
1357
|
-
'Content-Type': undefined
|
1358
|
-
};
|
1359
|
-
|
1360
1357
|
/**
|
1361
1358
|
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
1362
1359
|
* of the input
|
@@ -1495,19 +1492,16 @@ const defaults = {
|
|
1495
1492
|
|
1496
1493
|
headers: {
|
1497
1494
|
common: {
|
1498
|
-
'Accept': 'application/json, text/plain, */*'
|
1495
|
+
'Accept': 'application/json, text/plain, */*',
|
1496
|
+
'Content-Type': undefined
|
1499
1497
|
}
|
1500
1498
|
}
|
1501
1499
|
};
|
1502
1500
|
|
1503
|
-
utils.forEach(['delete', 'get', 'head'],
|
1501
|
+
utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
|
1504
1502
|
defaults.headers[method] = {};
|
1505
1503
|
});
|
1506
1504
|
|
1507
|
-
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
1508
|
-
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
1509
|
-
});
|
1510
|
-
|
1511
1505
|
const defaults$1 = defaults;
|
1512
1506
|
|
1513
1507
|
// RawAxiosHeaders whose duplicates are ignored by node
|
@@ -1841,7 +1835,17 @@ class AxiosHeaders {
|
|
1841
1835
|
|
1842
1836
|
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
1843
1837
|
|
1844
|
-
|
1838
|
+
// reserved names hotfix
|
1839
|
+
utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
|
1840
|
+
let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
|
1841
|
+
return {
|
1842
|
+
get: () => value,
|
1843
|
+
set(headerValue) {
|
1844
|
+
this[mapped] = headerValue;
|
1845
|
+
}
|
1846
|
+
}
|
1847
|
+
});
|
1848
|
+
|
1845
1849
|
utils.freezeMethods(AxiosHeaders);
|
1846
1850
|
|
1847
1851
|
const AxiosHeaders$1 = AxiosHeaders;
|
@@ -1961,7 +1965,7 @@ function buildFullPath(baseURL, requestedURL) {
|
|
1961
1965
|
return requestedURL;
|
1962
1966
|
}
|
1963
1967
|
|
1964
|
-
const VERSION = "1.
|
1968
|
+
const VERSION = "1.6.0";
|
1965
1969
|
|
1966
1970
|
function parseProtocol(url) {
|
1967
1971
|
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
@@ -2565,6 +2569,18 @@ const wrapAsync = (asyncExecutor) => {
|
|
2565
2569
|
})
|
2566
2570
|
};
|
2567
2571
|
|
2572
|
+
const resolveFamily = ({address, family}) => {
|
2573
|
+
if (!utils.isString(address)) {
|
2574
|
+
throw TypeError('address must be a string');
|
2575
|
+
}
|
2576
|
+
return ({
|
2577
|
+
address,
|
2578
|
+
family: family || (address.indexOf('.') < 0 ? 6 : 4)
|
2579
|
+
});
|
2580
|
+
};
|
2581
|
+
|
2582
|
+
const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(address) ? address : {address, family});
|
2583
|
+
|
2568
2584
|
/*eslint consistent-return:0*/
|
2569
2585
|
const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
2570
2586
|
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
|
@@ -2575,15 +2591,16 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
2575
2591
|
let rejected = false;
|
2576
2592
|
let req;
|
2577
2593
|
|
2578
|
-
if (lookup
|
2579
|
-
|
2580
|
-
|
2581
|
-
|
2582
|
-
|
2583
|
-
|
2584
|
-
|
2585
|
-
|
2586
|
-
|
2594
|
+
if (lookup) {
|
2595
|
+
const _lookup = callbackify$1(lookup, (value) => utils.isArray(value) ? value : [value]);
|
2596
|
+
// hotfix to support opt.all option which is required for node 20.x
|
2597
|
+
lookup = (hostname, opt, cb) => {
|
2598
|
+
_lookup(hostname, opt, (err, arg0, arg1) => {
|
2599
|
+
const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
|
2600
|
+
|
2601
|
+
opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
|
2602
|
+
});
|
2603
|
+
};
|
2587
2604
|
}
|
2588
2605
|
|
2589
2606
|
// temporary internal emitter until the AxiosRequest class will be implemented
|
@@ -2810,11 +2827,13 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
2810
2827
|
auth,
|
2811
2828
|
protocol,
|
2812
2829
|
family,
|
2813
|
-
lookup,
|
2814
2830
|
beforeRedirect: dispatchBeforeRedirect,
|
2815
2831
|
beforeRedirects: {}
|
2816
2832
|
};
|
2817
2833
|
|
2834
|
+
// cacheable-lookup integration hotfix
|
2835
|
+
!utils.isUndefined(lookup) && (options.lookup = lookup);
|
2836
|
+
|
2818
2837
|
if (config.socketPath) {
|
2819
2838
|
options.socketPath = config.socketPath;
|
2820
2839
|
} else {
|
@@ -2888,7 +2907,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
2888
2907
|
delete res.headers['content-encoding'];
|
2889
2908
|
}
|
2890
2909
|
|
2891
|
-
switch (res.headers['content-encoding']) {
|
2910
|
+
switch ((res.headers['content-encoding'] || '').toLowerCase()) {
|
2892
2911
|
/*eslint default-case:0*/
|
2893
2912
|
case 'gzip':
|
2894
2913
|
case 'x-gzip':
|
@@ -2984,7 +3003,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
2984
3003
|
}
|
2985
3004
|
response.data = responseData;
|
2986
3005
|
} catch (err) {
|
2987
|
-
reject(AxiosError.from(err, null, config, response.request, response));
|
3006
|
+
return reject(AxiosError.from(err, null, config, response.request, response));
|
2988
3007
|
}
|
2989
3008
|
settle(resolve, reject, response);
|
2990
3009
|
});
|
@@ -3021,7 +3040,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
3021
3040
|
// This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
|
3022
3041
|
const timeout = parseInt(config.timeout, 10);
|
3023
3042
|
|
3024
|
-
if (isNaN(timeout)) {
|
3043
|
+
if (Number.isNaN(timeout)) {
|
3025
3044
|
reject(new AxiosError(
|
3026
3045
|
'error trying to parse `config.timeout` to int',
|
3027
3046
|
AxiosError.ERR_BAD_OPTION_VALUE,
|
@@ -3240,11 +3259,16 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
3240
3259
|
}
|
3241
3260
|
}
|
3242
3261
|
|
3262
|
+
let contentType;
|
3263
|
+
|
3243
3264
|
if (utils.isFormData(requestData)) {
|
3244
3265
|
if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
|
3245
3266
|
requestHeaders.setContentType(false); // Let the browser set it
|
3246
|
-
} else {
|
3247
|
-
requestHeaders.setContentType('multipart/form-data
|
3267
|
+
} else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
|
3268
|
+
requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
|
3269
|
+
} else if(utils.isString(contentType = requestHeaders.getContentType())){
|
3270
|
+
// fix semicolon duplication issue for ReactNative FormData implementation
|
3271
|
+
requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'));
|
3248
3272
|
}
|
3249
3273
|
}
|
3250
3274
|
|
@@ -3362,8 +3386,8 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
3362
3386
|
// Specifically not if we're in a web worker, or react-native.
|
3363
3387
|
if (platform.isStandardBrowserEnv) {
|
3364
3388
|
// Add xsrf header
|
3365
|
-
|
3366
|
-
|
3389
|
+
// regarding CVE-2023-45857 config.withCredentials condition was removed temporarily
|
3390
|
+
const xsrfValue = isURLSameOrigin(fullPath) && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
|
3367
3391
|
|
3368
3392
|
if (xsrfValue) {
|
3369
3393
|
requestHeaders.set(config.xsrfHeaderName, xsrfValue);
|
@@ -3437,7 +3461,7 @@ const knownAdapters = {
|
|
3437
3461
|
};
|
3438
3462
|
|
3439
3463
|
utils.forEach(knownAdapters, (fn, value) => {
|
3440
|
-
if(fn) {
|
3464
|
+
if (fn) {
|
3441
3465
|
try {
|
3442
3466
|
Object.defineProperty(fn, 'name', {value});
|
3443
3467
|
} catch (e) {
|
@@ -3447,6 +3471,10 @@ utils.forEach(knownAdapters, (fn, value) => {
|
|
3447
3471
|
}
|
3448
3472
|
});
|
3449
3473
|
|
3474
|
+
const renderReason = (reason) => `- ${reason}`;
|
3475
|
+
|
3476
|
+
const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
|
3477
|
+
|
3450
3478
|
const adapters = {
|
3451
3479
|
getAdapter: (adapters) => {
|
3452
3480
|
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
@@ -3455,30 +3483,44 @@ const adapters = {
|
|
3455
3483
|
let nameOrAdapter;
|
3456
3484
|
let adapter;
|
3457
3485
|
|
3486
|
+
const rejectedReasons = {};
|
3487
|
+
|
3458
3488
|
for (let i = 0; i < length; i++) {
|
3459
3489
|
nameOrAdapter = adapters[i];
|
3460
|
-
|
3490
|
+
let id;
|
3491
|
+
|
3492
|
+
adapter = nameOrAdapter;
|
3493
|
+
|
3494
|
+
if (!isResolvedHandle(nameOrAdapter)) {
|
3495
|
+
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
3496
|
+
|
3497
|
+
if (adapter === undefined) {
|
3498
|
+
throw new AxiosError(`Unknown adapter '${id}'`);
|
3499
|
+
}
|
3500
|
+
}
|
3501
|
+
|
3502
|
+
if (adapter) {
|
3461
3503
|
break;
|
3462
3504
|
}
|
3505
|
+
|
3506
|
+
rejectedReasons[id || '#' + i] = adapter;
|
3463
3507
|
}
|
3464
3508
|
|
3465
3509
|
if (!adapter) {
|
3466
|
-
|
3467
|
-
|
3468
|
-
|
3469
|
-
'
|
3510
|
+
|
3511
|
+
const reasons = Object.entries(rejectedReasons)
|
3512
|
+
.map(([id, state]) => `adapter ${id} ` +
|
3513
|
+
(state === false ? 'is not supported by the environment' : 'is not available in the build')
|
3470
3514
|
);
|
3471
|
-
}
|
3472
3515
|
|
3473
|
-
|
3474
|
-
|
3475
|
-
|
3476
|
-
`Unknown adapter '${nameOrAdapter}'`
|
3477
|
-
);
|
3478
|
-
}
|
3516
|
+
let s = length ?
|
3517
|
+
(reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
|
3518
|
+
'as no adapter specified';
|
3479
3519
|
|
3480
|
-
|
3481
|
-
|
3520
|
+
throw new AxiosError(
|
3521
|
+
`There is no suitable adapter to dispatch the request ` + s,
|
3522
|
+
'ERR_NOT_SUPPORT'
|
3523
|
+
);
|
3482
3524
|
}
|
3483
3525
|
|
3484
3526
|
return adapter;
|
@@ -3811,15 +3853,13 @@ class Axios {
|
|
3811
3853
|
// Set config.method
|
3812
3854
|
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
3813
3855
|
|
3814
|
-
let contextHeaders;
|
3815
|
-
|
3816
3856
|
// Flatten headers
|
3817
|
-
contextHeaders = headers && utils.merge(
|
3857
|
+
let contextHeaders = headers && utils.merge(
|
3818
3858
|
headers.common,
|
3819
3859
|
headers[config.method]
|
3820
3860
|
);
|
3821
3861
|
|
3822
|
-
|
3862
|
+
headers && utils.forEach(
|
3823
3863
|
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
3824
3864
|
(method) => {
|
3825
3865
|
delete headers[method];
|
@@ -4229,6 +4269,8 @@ axios.AxiosHeaders = AxiosHeaders$1;
|
|
4229
4269
|
|
4230
4270
|
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
4231
4271
|
|
4272
|
+
axios.getAdapter = adapters.getAdapter;
|
4273
|
+
|
4232
4274
|
axios.HttpStatusCode = HttpStatusCode$1;
|
4233
4275
|
|
4234
4276
|
axios.default = axios;
|