axios 1.10.0 → 1.12.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/CHANGELOG.md +52 -0
- package/README.md +13 -13
- package/dist/axios.js +395 -292
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +2 -2
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +329 -217
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +329 -217
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +2 -2
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +420 -217
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +22 -7
- package/index.d.ts +10 -4
- package/lib/adapters/adapters.js +6 -4
- package/lib/adapters/fetch.js +220 -163
- package/lib/adapters/http.js +18 -0
- package/lib/adapters/xhr.js +11 -8
- package/lib/core/Axios.js +2 -2
- package/lib/core/AxiosError.js +10 -3
- package/lib/core/dispatchRequest.js +1 -1
- package/lib/core/mergeConfig.js +1 -1
- package/lib/defaults/index.js +1 -1
- package/lib/env/data.js +1 -1
- package/lib/helpers/buildURL.js +1 -3
- package/lib/helpers/estimateDataURLDecodedBytes.js +73 -0
- package/lib/helpers/resolveConfig.js +13 -9
- package/lib/helpers/throttle.js +1 -1
- package/lib/helpers/toURLEncodedForm.js +4 -3
- package/lib/utils.js +42 -2
- package/package.json +15 -12
package/dist/browser/axios.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! Axios v1.
|
|
1
|
+
/*! Axios v1.12.0 Copyright (c) 2025 Matt Zabriskie and contributors */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
function bind(fn, thisArg) {
|
|
@@ -52,7 +52,7 @@ const isUndefined = typeOfTest('undefined');
|
|
|
52
52
|
*/
|
|
53
53
|
function isBuffer(val) {
|
|
54
54
|
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
55
|
-
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
55
|
+
&& isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -97,7 +97,7 @@ const isString = typeOfTest('string');
|
|
|
97
97
|
* @param {*} val The value to test
|
|
98
98
|
* @returns {boolean} True if value is a Function, otherwise false
|
|
99
99
|
*/
|
|
100
|
-
const isFunction = typeOfTest('function');
|
|
100
|
+
const isFunction$1 = typeOfTest('function');
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Determine if a value is a Number
|
|
@@ -141,6 +141,27 @@ const isPlainObject = (val) => {
|
|
|
141
141
|
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Determine if a value is an empty object (safely handles Buffers)
|
|
146
|
+
*
|
|
147
|
+
* @param {*} val The value to test
|
|
148
|
+
*
|
|
149
|
+
* @returns {boolean} True if value is an empty object, otherwise false
|
|
150
|
+
*/
|
|
151
|
+
const isEmptyObject = (val) => {
|
|
152
|
+
// Early return for non-objects or Buffers to prevent RangeError
|
|
153
|
+
if (!isObject(val) || isBuffer(val)) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
159
|
+
} catch (e) {
|
|
160
|
+
// Fallback for any other objects that might cause RangeError with Object.keys()
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
144
165
|
/**
|
|
145
166
|
* Determine if a value is a Date
|
|
146
167
|
*
|
|
@@ -184,7 +205,7 @@ const isFileList = kindOfTest('FileList');
|
|
|
184
205
|
*
|
|
185
206
|
* @returns {boolean} True if value is a Stream, otherwise false
|
|
186
207
|
*/
|
|
187
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
|
208
|
+
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
188
209
|
|
|
189
210
|
/**
|
|
190
211
|
* Determine if a value is a FormData
|
|
@@ -197,10 +218,10 @@ const isFormData = (thing) => {
|
|
|
197
218
|
let kind;
|
|
198
219
|
return thing && (
|
|
199
220
|
(typeof FormData === 'function' && thing instanceof FormData) || (
|
|
200
|
-
isFunction(thing.append) && (
|
|
221
|
+
isFunction$1(thing.append) && (
|
|
201
222
|
(kind = kindOf(thing)) === 'formdata' ||
|
|
202
223
|
// detect form-data instance
|
|
203
|
-
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
|
|
224
|
+
(kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
|
|
204
225
|
)
|
|
205
226
|
)
|
|
206
227
|
)
|
|
@@ -263,6 +284,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
263
284
|
fn.call(null, obj[i], i, obj);
|
|
264
285
|
}
|
|
265
286
|
} else {
|
|
287
|
+
// Buffer check
|
|
288
|
+
if (isBuffer(obj)) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
266
292
|
// Iterate over object keys
|
|
267
293
|
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
268
294
|
const len = keys.length;
|
|
@@ -276,6 +302,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
276
302
|
}
|
|
277
303
|
|
|
278
304
|
function findKey(obj, key) {
|
|
305
|
+
if (isBuffer(obj)){
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
|
|
279
309
|
key = key.toLowerCase();
|
|
280
310
|
const keys = Object.keys(obj);
|
|
281
311
|
let i = keys.length;
|
|
@@ -316,7 +346,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
|
|
|
316
346
|
* @returns {Object} Result of all merge properties
|
|
317
347
|
*/
|
|
318
348
|
function merge(/* obj1, obj2, obj3, ... */) {
|
|
319
|
-
const {caseless} = isContextDefined(this) && this || {};
|
|
349
|
+
const {caseless, skipUndefined} = isContextDefined(this) && this || {};
|
|
320
350
|
const result = {};
|
|
321
351
|
const assignValue = (val, key) => {
|
|
322
352
|
const targetKey = caseless && findKey(result, key) || key;
|
|
@@ -327,7 +357,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
327
357
|
} else if (isArray(val)) {
|
|
328
358
|
result[targetKey] = val.slice();
|
|
329
359
|
} else {
|
|
330
|
-
|
|
360
|
+
if (!skipUndefined || !isUndefined(val)) {
|
|
361
|
+
result[targetKey] = val;
|
|
362
|
+
}
|
|
331
363
|
}
|
|
332
364
|
};
|
|
333
365
|
|
|
@@ -349,7 +381,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
349
381
|
*/
|
|
350
382
|
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
|
351
383
|
forEach(b, (val, key) => {
|
|
352
|
-
if (thisArg && isFunction(val)) {
|
|
384
|
+
if (thisArg && isFunction$1(val)) {
|
|
353
385
|
a[key] = bind(val, thisArg);
|
|
354
386
|
} else {
|
|
355
387
|
a[key] = val;
|
|
@@ -565,13 +597,13 @@ const reduceDescriptors = (obj, reducer) => {
|
|
|
565
597
|
const freezeMethods = (obj) => {
|
|
566
598
|
reduceDescriptors(obj, (descriptor, name) => {
|
|
567
599
|
// skip restricted props in strict mode
|
|
568
|
-
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
600
|
+
if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
569
601
|
return false;
|
|
570
602
|
}
|
|
571
603
|
|
|
572
604
|
const value = obj[name];
|
|
573
605
|
|
|
574
|
-
if (!isFunction(value)) return;
|
|
606
|
+
if (!isFunction$1(value)) return;
|
|
575
607
|
|
|
576
608
|
descriptor.enumerable = false;
|
|
577
609
|
|
|
@@ -608,6 +640,8 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
608
640
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
609
641
|
};
|
|
610
642
|
|
|
643
|
+
|
|
644
|
+
|
|
611
645
|
/**
|
|
612
646
|
* If the thing is a FormData object, return true, otherwise return false.
|
|
613
647
|
*
|
|
@@ -616,7 +650,7 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
616
650
|
* @returns {boolean}
|
|
617
651
|
*/
|
|
618
652
|
function isSpecCompliantForm(thing) {
|
|
619
|
-
return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|
653
|
+
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|
620
654
|
}
|
|
621
655
|
|
|
622
656
|
const toJSONObject = (obj) => {
|
|
@@ -629,6 +663,11 @@ const toJSONObject = (obj) => {
|
|
|
629
663
|
return;
|
|
630
664
|
}
|
|
631
665
|
|
|
666
|
+
//Buffer check
|
|
667
|
+
if (isBuffer(source)) {
|
|
668
|
+
return source;
|
|
669
|
+
}
|
|
670
|
+
|
|
632
671
|
if(!('toJSON' in source)) {
|
|
633
672
|
stack[i] = source;
|
|
634
673
|
const target = isArray(source) ? [] : {};
|
|
@@ -653,7 +692,7 @@ const toJSONObject = (obj) => {
|
|
|
653
692
|
const isAsyncFn = kindOfTest('AsyncFunction');
|
|
654
693
|
|
|
655
694
|
const isThenable = (thing) =>
|
|
656
|
-
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
|
695
|
+
thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
657
696
|
|
|
658
697
|
// original code
|
|
659
698
|
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|
@@ -677,7 +716,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
677
716
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
678
717
|
})(
|
|
679
718
|
typeof setImmediate === 'function',
|
|
680
|
-
isFunction(_global.postMessage)
|
|
719
|
+
isFunction$1(_global.postMessage)
|
|
681
720
|
);
|
|
682
721
|
|
|
683
722
|
const asap = typeof queueMicrotask !== 'undefined' ?
|
|
@@ -686,7 +725,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
|
|
|
686
725
|
// *********************
|
|
687
726
|
|
|
688
727
|
|
|
689
|
-
const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
|
|
728
|
+
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
690
729
|
|
|
691
730
|
|
|
692
731
|
var utils$1 = {
|
|
@@ -700,6 +739,7 @@ var utils$1 = {
|
|
|
700
739
|
isBoolean,
|
|
701
740
|
isObject,
|
|
702
741
|
isPlainObject,
|
|
742
|
+
isEmptyObject,
|
|
703
743
|
isReadableStream,
|
|
704
744
|
isRequest,
|
|
705
745
|
isResponse,
|
|
@@ -709,7 +749,7 @@ var utils$1 = {
|
|
|
709
749
|
isFile,
|
|
710
750
|
isBlob,
|
|
711
751
|
isRegExp,
|
|
712
|
-
isFunction,
|
|
752
|
+
isFunction: isFunction$1,
|
|
713
753
|
isStream,
|
|
714
754
|
isURLSearchParams,
|
|
715
755
|
isTypedArray,
|
|
@@ -835,11 +875,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
|
835
875
|
return prop !== 'isAxiosError';
|
|
836
876
|
});
|
|
837
877
|
|
|
838
|
-
|
|
878
|
+
const msg = error && error.message ? error.message : 'Error';
|
|
879
|
+
|
|
880
|
+
// Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
|
|
881
|
+
const errCode = code == null && error ? error.code : code;
|
|
882
|
+
AxiosError.call(axiosError, msg, errCode, config, request, response);
|
|
839
883
|
|
|
840
|
-
|
|
884
|
+
// Chain the original error on the standard field; non-enumerable to avoid JSON noise
|
|
885
|
+
if (error && axiosError.cause == null) {
|
|
886
|
+
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
|
|
887
|
+
}
|
|
841
888
|
|
|
842
|
-
axiosError.name = error.name;
|
|
889
|
+
axiosError.name = (error && error.name) || 'Error';
|
|
843
890
|
|
|
844
891
|
customProps && Object.assign(axiosError, customProps);
|
|
845
892
|
|
|
@@ -1130,9 +1177,7 @@ function encode(val) {
|
|
|
1130
1177
|
replace(/%3A/gi, ':').
|
|
1131
1178
|
replace(/%24/g, '$').
|
|
1132
1179
|
replace(/%2C/gi, ',').
|
|
1133
|
-
replace(/%20/g, '+')
|
|
1134
|
-
replace(/%5B/gi, '[').
|
|
1135
|
-
replace(/%5D/gi, ']');
|
|
1180
|
+
replace(/%20/g, '+');
|
|
1136
1181
|
}
|
|
1137
1182
|
|
|
1138
1183
|
/**
|
|
@@ -1331,7 +1376,7 @@ var platform = {
|
|
|
1331
1376
|
};
|
|
1332
1377
|
|
|
1333
1378
|
function toURLEncodedForm(data, options) {
|
|
1334
|
-
return toFormData(data, new platform.classes.URLSearchParams(),
|
|
1379
|
+
return toFormData(data, new platform.classes.URLSearchParams(), {
|
|
1335
1380
|
visitor: function(value, key, path, helpers) {
|
|
1336
1381
|
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
1337
1382
|
this.append(key, value.toString('base64'));
|
|
@@ -1339,8 +1384,9 @@ function toURLEncodedForm(data, options) {
|
|
|
1339
1384
|
}
|
|
1340
1385
|
|
|
1341
1386
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
1342
|
-
}
|
|
1343
|
-
|
|
1387
|
+
},
|
|
1388
|
+
...options
|
|
1389
|
+
});
|
|
1344
1390
|
}
|
|
1345
1391
|
|
|
1346
1392
|
/**
|
|
@@ -1536,7 +1582,7 @@ const defaults = {
|
|
|
1536
1582
|
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1537
1583
|
|
|
1538
1584
|
try {
|
|
1539
|
-
return JSON.parse(data);
|
|
1585
|
+
return JSON.parse(data, this.parseReviver);
|
|
1540
1586
|
} catch (e) {
|
|
1541
1587
|
if (strictJSONParsing) {
|
|
1542
1588
|
if (e.name === 'SyntaxError') {
|
|
@@ -2093,7 +2139,7 @@ function throttle(fn, freq) {
|
|
|
2093
2139
|
clearTimeout(timer);
|
|
2094
2140
|
timer = null;
|
|
2095
2141
|
}
|
|
2096
|
-
fn
|
|
2142
|
+
fn(...args);
|
|
2097
2143
|
};
|
|
2098
2144
|
|
|
2099
2145
|
const throttled = (...args) => {
|
|
@@ -2349,7 +2395,7 @@ function mergeConfig(config1, config2) {
|
|
|
2349
2395
|
headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
|
|
2350
2396
|
};
|
|
2351
2397
|
|
|
2352
|
-
utils$1.forEach(Object.keys(
|
|
2398
|
+
utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
|
|
2353
2399
|
const merge = mergeMap[prop] || mergeDeepProperties;
|
|
2354
2400
|
const configValue = merge(config1[prop], config2[prop], prop);
|
|
2355
2401
|
(utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
@@ -2361,7 +2407,7 @@ function mergeConfig(config1, config2) {
|
|
|
2361
2407
|
var resolveConfig = (config) => {
|
|
2362
2408
|
const newConfig = mergeConfig({}, config);
|
|
2363
2409
|
|
|
2364
|
-
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
|
2410
|
+
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
2365
2411
|
|
|
2366
2412
|
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
|
2367
2413
|
|
|
@@ -2374,17 +2420,21 @@ var resolveConfig = (config) => {
|
|
|
2374
2420
|
);
|
|
2375
2421
|
}
|
|
2376
2422
|
|
|
2377
|
-
let contentType;
|
|
2378
|
-
|
|
2379
2423
|
if (utils$1.isFormData(data)) {
|
|
2380
2424
|
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2381
|
-
headers.setContentType(undefined); //
|
|
2382
|
-
} else if ((
|
|
2383
|
-
//
|
|
2384
|
-
const
|
|
2385
|
-
headers
|
|
2425
|
+
headers.setContentType(undefined); // browser handles it
|
|
2426
|
+
} else if (utils$1.isFunction(data.getHeaders)) {
|
|
2427
|
+
// Node.js FormData (like form-data package)
|
|
2428
|
+
const formHeaders = data.getHeaders();
|
|
2429
|
+
// Only set safe headers to avoid overwriting security headers
|
|
2430
|
+
const allowedHeaders = ['content-type', 'content-length'];
|
|
2431
|
+
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
2432
|
+
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
2433
|
+
headers.set(key, val);
|
|
2434
|
+
}
|
|
2435
|
+
});
|
|
2386
2436
|
}
|
|
2387
|
-
}
|
|
2437
|
+
}
|
|
2388
2438
|
|
|
2389
2439
|
// Add xsrf header
|
|
2390
2440
|
// This is only done if running in a standard browser environment.
|
|
@@ -2501,15 +2551,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
|
2501
2551
|
};
|
|
2502
2552
|
|
|
2503
2553
|
// Handle low level network errors
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2554
|
+
request.onerror = function handleError(event) {
|
|
2555
|
+
// Browsers deliver a ProgressEvent in XHR onerror
|
|
2556
|
+
// (message may be empty; when present, surface it)
|
|
2557
|
+
// See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
|
|
2558
|
+
const msg = event && event.message ? event.message : 'Network Error';
|
|
2559
|
+
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
|
2560
|
+
// attach the underlying event for consumers who want details
|
|
2561
|
+
err.event = event || null;
|
|
2562
|
+
reject(err);
|
|
2563
|
+
request = null;
|
|
2511
2564
|
};
|
|
2512
|
-
|
|
2565
|
+
|
|
2513
2566
|
// Handle timeout
|
|
2514
2567
|
request.ontimeout = function handleTimeout() {
|
|
2515
2568
|
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
@@ -2725,14 +2778,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
2725
2778
|
})
|
|
2726
2779
|
};
|
|
2727
2780
|
|
|
2728
|
-
const
|
|
2729
|
-
|
|
2781
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2782
|
+
|
|
2783
|
+
const {isFunction} = utils$1;
|
|
2784
|
+
|
|
2785
|
+
const globalFetchAPI = (({fetch, Request, Response}) => ({
|
|
2786
|
+
fetch, Request, Response
|
|
2787
|
+
}))(utils$1.global);
|
|
2788
|
+
|
|
2789
|
+
const {
|
|
2790
|
+
ReadableStream: ReadableStream$1, TextEncoder
|
|
2791
|
+
} = utils$1.global;
|
|
2730
2792
|
|
|
2731
|
-
// used only inside the fetch adapter
|
|
2732
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
2733
|
-
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
2734
|
-
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
|
2735
|
-
);
|
|
2736
2793
|
|
|
2737
2794
|
const test = (fn, ...args) => {
|
|
2738
2795
|
try {
|
|
@@ -2742,211 +2799,266 @@ const test = (fn, ...args) => {
|
|
|
2742
2799
|
}
|
|
2743
2800
|
};
|
|
2744
2801
|
|
|
2745
|
-
const
|
|
2746
|
-
|
|
2802
|
+
const factory = (env) => {
|
|
2803
|
+
const {fetch, Request, Response} = Object.assign({}, globalFetchAPI, env);
|
|
2804
|
+
const isFetchSupported = isFunction(fetch);
|
|
2805
|
+
const isRequestSupported = isFunction(Request);
|
|
2806
|
+
const isResponseSupported = isFunction(Response);
|
|
2747
2807
|
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
get duplex() {
|
|
2752
|
-
duplexAccessed = true;
|
|
2753
|
-
return 'half';
|
|
2754
|
-
},
|
|
2755
|
-
}).headers.has('Content-Type');
|
|
2808
|
+
if (!isFetchSupported) {
|
|
2809
|
+
return false;
|
|
2810
|
+
}
|
|
2756
2811
|
|
|
2757
|
-
|
|
2758
|
-
});
|
|
2812
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
|
|
2759
2813
|
|
|
2760
|
-
const
|
|
2814
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
2815
|
+
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
2816
|
+
async (str) => new Uint8Array(await new Request(str).arrayBuffer())
|
|
2817
|
+
);
|
|
2761
2818
|
|
|
2762
|
-
const
|
|
2763
|
-
|
|
2819
|
+
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
2820
|
+
let duplexAccessed = false;
|
|
2764
2821
|
|
|
2822
|
+
const hasContentType = new Request(platform.origin, {
|
|
2823
|
+
body: new ReadableStream$1(),
|
|
2824
|
+
method: 'POST',
|
|
2825
|
+
get duplex() {
|
|
2826
|
+
duplexAccessed = true;
|
|
2827
|
+
return 'half';
|
|
2828
|
+
},
|
|
2829
|
+
}).headers.has('Content-Type');
|
|
2765
2830
|
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2831
|
+
return duplexAccessed && !hasContentType;
|
|
2832
|
+
});
|
|
2833
|
+
|
|
2834
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
|
|
2835
|
+
test(() => utils$1.isReadableStream(new Response('').body));
|
|
2836
|
+
|
|
2837
|
+
const resolvers = {
|
|
2838
|
+
stream: supportsResponseStream && ((res) => res.body)
|
|
2839
|
+
};
|
|
2840
|
+
|
|
2841
|
+
isFetchSupported && ((() => {
|
|
2842
|
+
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
2843
|
+
!resolvers[type] && (resolvers[type] = (res, config) => {
|
|
2844
|
+
let method = res && res[type];
|
|
2845
|
+
|
|
2846
|
+
if (method) {
|
|
2847
|
+
return method.call(res);
|
|
2848
|
+
}
|
|
2769
2849
|
|
|
2770
|
-
isFetchSupported && (((res) => {
|
|
2771
|
-
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
2772
|
-
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
|
|
2773
|
-
(_, config) => {
|
|
2774
2850
|
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
2775
2851
|
});
|
|
2776
|
-
|
|
2777
|
-
})(
|
|
2852
|
+
});
|
|
2853
|
+
})());
|
|
2778
2854
|
|
|
2779
|
-
const getBodyLength = async (body) => {
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2855
|
+
const getBodyLength = async (body) => {
|
|
2856
|
+
if (body == null) {
|
|
2857
|
+
return 0;
|
|
2858
|
+
}
|
|
2783
2859
|
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2860
|
+
if (utils$1.isBlob(body)) {
|
|
2861
|
+
return body.size;
|
|
2862
|
+
}
|
|
2787
2863
|
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2864
|
+
if (utils$1.isSpecCompliantForm(body)) {
|
|
2865
|
+
const _request = new Request(platform.origin, {
|
|
2866
|
+
method: 'POST',
|
|
2867
|
+
body,
|
|
2868
|
+
});
|
|
2869
|
+
return (await _request.arrayBuffer()).byteLength;
|
|
2870
|
+
}
|
|
2795
2871
|
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2872
|
+
if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|
2873
|
+
return body.byteLength;
|
|
2874
|
+
}
|
|
2799
2875
|
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2876
|
+
if (utils$1.isURLSearchParams(body)) {
|
|
2877
|
+
body = body + '';
|
|
2878
|
+
}
|
|
2803
2879
|
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
};
|
|
2880
|
+
if (utils$1.isString(body)) {
|
|
2881
|
+
return (await encodeText(body)).byteLength;
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2808
2884
|
|
|
2809
|
-
const resolveBodyLength = async (headers, body) => {
|
|
2810
|
-
|
|
2885
|
+
const resolveBodyLength = async (headers, body) => {
|
|
2886
|
+
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|
2811
2887
|
|
|
2812
|
-
|
|
2813
|
-
};
|
|
2888
|
+
return length == null ? getBodyLength(body) : length;
|
|
2889
|
+
};
|
|
2814
2890
|
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2891
|
+
return async (config) => {
|
|
2892
|
+
let {
|
|
2893
|
+
url,
|
|
2894
|
+
method,
|
|
2895
|
+
data,
|
|
2896
|
+
signal,
|
|
2897
|
+
cancelToken,
|
|
2898
|
+
timeout,
|
|
2899
|
+
onDownloadProgress,
|
|
2900
|
+
onUploadProgress,
|
|
2901
|
+
responseType,
|
|
2902
|
+
headers,
|
|
2903
|
+
withCredentials = 'same-origin',
|
|
2904
|
+
fetchOptions
|
|
2905
|
+
} = resolveConfig(config);
|
|
2906
|
+
|
|
2907
|
+
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
2908
|
+
|
|
2909
|
+
let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
2910
|
+
|
|
2911
|
+
let request = null;
|
|
2912
|
+
|
|
2913
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
2838
2914
|
composedSignal.unsubscribe();
|
|
2839
|
-
|
|
2915
|
+
});
|
|
2840
2916
|
|
|
2841
|
-
|
|
2917
|
+
let requestContentLength;
|
|
2842
2918
|
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2919
|
+
try {
|
|
2920
|
+
if (
|
|
2921
|
+
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
|
2922
|
+
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
|
2923
|
+
) {
|
|
2924
|
+
let _request = new Request(url, {
|
|
2925
|
+
method: 'POST',
|
|
2926
|
+
body: data,
|
|
2927
|
+
duplex: "half"
|
|
2928
|
+
});
|
|
2853
2929
|
|
|
2854
|
-
|
|
2930
|
+
let contentTypeHeader;
|
|
2855
2931
|
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2932
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
|
2933
|
+
headers.setContentType(contentTypeHeader);
|
|
2934
|
+
}
|
|
2859
2935
|
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2936
|
+
if (_request.body) {
|
|
2937
|
+
const [onProgress, flush] = progressEventDecorator(
|
|
2938
|
+
requestContentLength,
|
|
2939
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
2940
|
+
);
|
|
2865
2941
|
|
|
2866
|
-
|
|
2942
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
2943
|
+
}
|
|
2867
2944
|
}
|
|
2868
|
-
}
|
|
2869
2945
|
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2946
|
+
if (!utils$1.isString(withCredentials)) {
|
|
2947
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
|
2948
|
+
}
|
|
2873
2949
|
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
request = new Request(url, {
|
|
2878
|
-
...fetchOptions,
|
|
2879
|
-
signal: composedSignal,
|
|
2880
|
-
method: method.toUpperCase(),
|
|
2881
|
-
headers: headers.normalize().toJSON(),
|
|
2882
|
-
body: data,
|
|
2883
|
-
duplex: "half",
|
|
2884
|
-
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
2885
|
-
});
|
|
2950
|
+
// Cloudflare Workers throws when credentials are defined
|
|
2951
|
+
// see https://github.com/cloudflare/workerd/issues/902
|
|
2952
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
2886
2953
|
|
|
2887
|
-
|
|
2954
|
+
const resolvedOptions = {
|
|
2955
|
+
...fetchOptions,
|
|
2956
|
+
signal: composedSignal,
|
|
2957
|
+
method: method.toUpperCase(),
|
|
2958
|
+
headers: headers.normalize().toJSON(),
|
|
2959
|
+
body: data,
|
|
2960
|
+
duplex: "half",
|
|
2961
|
+
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
2962
|
+
};
|
|
2888
2963
|
|
|
2889
|
-
|
|
2964
|
+
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
2890
2965
|
|
|
2891
|
-
|
|
2892
|
-
const options = {};
|
|
2966
|
+
let response = await (isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions));
|
|
2893
2967
|
|
|
2894
|
-
|
|
2895
|
-
options[prop] = response[prop];
|
|
2896
|
-
});
|
|
2968
|
+
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
|
2897
2969
|
|
|
2898
|
-
|
|
2970
|
+
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
|
2971
|
+
const options = {};
|
|
2899
2972
|
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
) || [];
|
|
2973
|
+
['status', 'statusText', 'headers'].forEach(prop => {
|
|
2974
|
+
options[prop] = response[prop];
|
|
2975
|
+
});
|
|
2904
2976
|
|
|
2905
|
-
|
|
2906
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
2907
|
-
flush && flush();
|
|
2908
|
-
unsubscribe && unsubscribe();
|
|
2909
|
-
}),
|
|
2910
|
-
options
|
|
2911
|
-
);
|
|
2912
|
-
}
|
|
2977
|
+
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|
2913
2978
|
|
|
2914
|
-
|
|
2979
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
2980
|
+
responseContentLength,
|
|
2981
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
2982
|
+
) || [];
|
|
2915
2983
|
|
|
2916
|
-
|
|
2984
|
+
response = new Response(
|
|
2985
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
2986
|
+
flush && flush();
|
|
2987
|
+
unsubscribe && unsubscribe();
|
|
2988
|
+
}),
|
|
2989
|
+
options
|
|
2990
|
+
);
|
|
2991
|
+
}
|
|
2917
2992
|
|
|
2918
|
-
|
|
2993
|
+
responseType = responseType || 'text';
|
|
2919
2994
|
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2995
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
|
2996
|
+
|
|
2997
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
|
2998
|
+
|
|
2999
|
+
return await new Promise((resolve, reject) => {
|
|
3000
|
+
settle(resolve, reject, {
|
|
3001
|
+
data: responseData,
|
|
3002
|
+
headers: AxiosHeaders$1.from(response.headers),
|
|
3003
|
+
status: response.status,
|
|
3004
|
+
statusText: response.statusText,
|
|
3005
|
+
config,
|
|
3006
|
+
request
|
|
3007
|
+
});
|
|
3008
|
+
})
|
|
3009
|
+
} catch (err) {
|
|
3010
|
+
unsubscribe && unsubscribe();
|
|
3011
|
+
|
|
3012
|
+
if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
|
3013
|
+
throw Object.assign(
|
|
3014
|
+
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
|
3015
|
+
{
|
|
3016
|
+
cause: err.cause || err
|
|
3017
|
+
}
|
|
3018
|
+
)
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
|
2940
3022
|
}
|
|
3023
|
+
}
|
|
3024
|
+
};
|
|
3025
|
+
|
|
3026
|
+
const seedCache = new Map();
|
|
3027
|
+
|
|
3028
|
+
const getFetch = (config) => {
|
|
3029
|
+
let env = utils$1.merge.call({
|
|
3030
|
+
skipUndefined: true
|
|
3031
|
+
}, globalFetchAPI, config ? config.env : null);
|
|
3032
|
+
|
|
3033
|
+
const {fetch, Request, Response} = env;
|
|
3034
|
+
|
|
3035
|
+
const seeds = [
|
|
3036
|
+
Request, Response, fetch
|
|
3037
|
+
];
|
|
2941
3038
|
|
|
2942
|
-
|
|
3039
|
+
let len = seeds.length, i = len,
|
|
3040
|
+
seed, target, map = seedCache;
|
|
3041
|
+
|
|
3042
|
+
while (i--) {
|
|
3043
|
+
seed = seeds[i];
|
|
3044
|
+
target = map.get(seed);
|
|
3045
|
+
|
|
3046
|
+
target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
|
|
3047
|
+
|
|
3048
|
+
map = target;
|
|
2943
3049
|
}
|
|
2944
|
-
|
|
3050
|
+
|
|
3051
|
+
return target;
|
|
3052
|
+
};
|
|
3053
|
+
|
|
3054
|
+
getFetch();
|
|
2945
3055
|
|
|
2946
3056
|
const knownAdapters = {
|
|
2947
3057
|
http: httpAdapter,
|
|
2948
3058
|
xhr: xhrAdapter,
|
|
2949
|
-
fetch:
|
|
3059
|
+
fetch: {
|
|
3060
|
+
get: getFetch,
|
|
3061
|
+
}
|
|
2950
3062
|
};
|
|
2951
3063
|
|
|
2952
3064
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
@@ -2965,7 +3077,7 @@ const renderReason = (reason) => `- ${reason}`;
|
|
|
2965
3077
|
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
2966
3078
|
|
|
2967
3079
|
var adapters = {
|
|
2968
|
-
getAdapter: (adapters) => {
|
|
3080
|
+
getAdapter: (adapters, config) => {
|
|
2969
3081
|
adapters = utils$1.isArray(adapters) ? adapters : [adapters];
|
|
2970
3082
|
|
|
2971
3083
|
const {length} = adapters;
|
|
@@ -2988,7 +3100,7 @@ var adapters = {
|
|
|
2988
3100
|
}
|
|
2989
3101
|
}
|
|
2990
3102
|
|
|
2991
|
-
if (adapter) {
|
|
3103
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
|
2992
3104
|
break;
|
|
2993
3105
|
}
|
|
2994
3106
|
|
|
@@ -3056,7 +3168,7 @@ function dispatchRequest(config) {
|
|
|
3056
3168
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
3057
3169
|
}
|
|
3058
3170
|
|
|
3059
|
-
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
|
|
3171
|
+
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
|
|
3060
3172
|
|
|
3061
3173
|
return adapter(config).then(function onAdapterResolution(response) {
|
|
3062
3174
|
throwIfCancellationRequested(config);
|
|
@@ -3090,7 +3202,7 @@ function dispatchRequest(config) {
|
|
|
3090
3202
|
});
|
|
3091
3203
|
}
|
|
3092
3204
|
|
|
3093
|
-
const VERSION = "1.
|
|
3205
|
+
const VERSION = "1.12.0";
|
|
3094
3206
|
|
|
3095
3207
|
const validators$1 = {};
|
|
3096
3208
|
|
|
@@ -3329,8 +3441,8 @@ class Axios {
|
|
|
3329
3441
|
|
|
3330
3442
|
if (!synchronousRequestInterceptors) {
|
|
3331
3443
|
const chain = [dispatchRequest.bind(this), undefined];
|
|
3332
|
-
chain.unshift
|
|
3333
|
-
chain.push
|
|
3444
|
+
chain.unshift(...requestInterceptorChain);
|
|
3445
|
+
chain.push(...responseInterceptorChain);
|
|
3334
3446
|
len = chain.length;
|
|
3335
3447
|
|
|
3336
3448
|
promise = Promise.resolve(config);
|