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