axios 1.7.9 → 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 +200 -0
- package/README.md +62 -37
- package/dist/axios.js +438 -327
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +2 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +369 -249
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +369 -249
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +2 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +491 -253
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +26 -10
- package/index.d.ts +16 -7
- package/lib/adapters/adapters.js +6 -4
- package/lib/adapters/fetch.js +220 -163
- package/lib/adapters/http.js +19 -1
- package/lib/adapters/xhr.js +11 -8
- package/lib/core/Axios.js +13 -4
- package/lib/core/AxiosError.js +10 -3
- package/lib/core/AxiosHeaders.js +15 -3
- package/lib/core/buildFullPath.js +3 -2
- 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/formDataToStream.js +4 -3
- package/lib/helpers/resolveConfig.js +14 -10
- package/lib/helpers/throttle.js +1 -1
- package/lib/helpers/toFormData.js +4 -0
- package/lib/helpers/toURLEncodedForm.js +4 -3
- package/lib/platform/node/index.js +26 -0
- package/lib/utils.js +52 -28
- package/package.json +24 -12
- package/SECURITY.md +0 -6
package/dist/node/axios.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/*! Axios v1.12.0 Copyright (c) 2025 Matt Zabriskie and contributors */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const FormData$1 = require('form-data');
|
|
5
|
+
const crypto = require('crypto');
|
|
5
6
|
const url = require('url');
|
|
6
7
|
const proxyFromEnv = require('proxy-from-env');
|
|
7
8
|
const http = require('http');
|
|
@@ -15,6 +16,7 @@ const events = require('events');
|
|
|
15
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
17
|
|
|
17
18
|
const FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData$1);
|
|
19
|
+
const crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
18
20
|
const url__default = /*#__PURE__*/_interopDefaultLegacy(url);
|
|
19
21
|
const proxyFromEnv__default = /*#__PURE__*/_interopDefaultLegacy(proxyFromEnv);
|
|
20
22
|
const http__default = /*#__PURE__*/_interopDefaultLegacy(http);
|
|
@@ -34,6 +36,7 @@ function bind(fn, thisArg) {
|
|
|
34
36
|
|
|
35
37
|
const {toString} = Object.prototype;
|
|
36
38
|
const {getPrototypeOf} = Object;
|
|
39
|
+
const {iterator, toStringTag} = Symbol;
|
|
37
40
|
|
|
38
41
|
const kindOf = (cache => thing => {
|
|
39
42
|
const str = toString.call(thing);
|
|
@@ -74,7 +77,7 @@ const isUndefined = typeOfTest('undefined');
|
|
|
74
77
|
*/
|
|
75
78
|
function isBuffer(val) {
|
|
76
79
|
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
77
|
-
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
80
|
+
&& isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
/**
|
|
@@ -119,7 +122,7 @@ const isString = typeOfTest('string');
|
|
|
119
122
|
* @param {*} val The value to test
|
|
120
123
|
* @returns {boolean} True if value is a Function, otherwise false
|
|
121
124
|
*/
|
|
122
|
-
const isFunction = typeOfTest('function');
|
|
125
|
+
const isFunction$1 = typeOfTest('function');
|
|
123
126
|
|
|
124
127
|
/**
|
|
125
128
|
* Determine if a value is a Number
|
|
@@ -160,7 +163,28 @@ const isPlainObject = (val) => {
|
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
const prototype = getPrototypeOf(val);
|
|
163
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(
|
|
166
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Determine if a value is an empty object (safely handles Buffers)
|
|
171
|
+
*
|
|
172
|
+
* @param {*} val The value to test
|
|
173
|
+
*
|
|
174
|
+
* @returns {boolean} True if value is an empty object, otherwise false
|
|
175
|
+
*/
|
|
176
|
+
const isEmptyObject = (val) => {
|
|
177
|
+
// Early return for non-objects or Buffers to prevent RangeError
|
|
178
|
+
if (!isObject(val) || isBuffer(val)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
184
|
+
} catch (e) {
|
|
185
|
+
// Fallback for any other objects that might cause RangeError with Object.keys()
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
164
188
|
};
|
|
165
189
|
|
|
166
190
|
/**
|
|
@@ -206,7 +230,7 @@ const isFileList = kindOfTest('FileList');
|
|
|
206
230
|
*
|
|
207
231
|
* @returns {boolean} True if value is a Stream, otherwise false
|
|
208
232
|
*/
|
|
209
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
|
233
|
+
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
210
234
|
|
|
211
235
|
/**
|
|
212
236
|
* Determine if a value is a FormData
|
|
@@ -219,10 +243,10 @@ const isFormData = (thing) => {
|
|
|
219
243
|
let kind;
|
|
220
244
|
return thing && (
|
|
221
245
|
(typeof FormData === 'function' && thing instanceof FormData) || (
|
|
222
|
-
isFunction(thing.append) && (
|
|
246
|
+
isFunction$1(thing.append) && (
|
|
223
247
|
(kind = kindOf(thing)) === 'formdata' ||
|
|
224
248
|
// detect form-data instance
|
|
225
|
-
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
|
|
249
|
+
(kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
|
|
226
250
|
)
|
|
227
251
|
)
|
|
228
252
|
)
|
|
@@ -285,6 +309,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
285
309
|
fn.call(null, obj[i], i, obj);
|
|
286
310
|
}
|
|
287
311
|
} else {
|
|
312
|
+
// Buffer check
|
|
313
|
+
if (isBuffer(obj)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
|
|
288
317
|
// Iterate over object keys
|
|
289
318
|
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
290
319
|
const len = keys.length;
|
|
@@ -298,6 +327,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
298
327
|
}
|
|
299
328
|
|
|
300
329
|
function findKey(obj, key) {
|
|
330
|
+
if (isBuffer(obj)){
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
|
|
301
334
|
key = key.toLowerCase();
|
|
302
335
|
const keys = Object.keys(obj);
|
|
303
336
|
let i = keys.length;
|
|
@@ -338,7 +371,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
|
|
|
338
371
|
* @returns {Object} Result of all merge properties
|
|
339
372
|
*/
|
|
340
373
|
function merge(/* obj1, obj2, obj3, ... */) {
|
|
341
|
-
const {caseless} = isContextDefined(this) && this || {};
|
|
374
|
+
const {caseless, skipUndefined} = isContextDefined(this) && this || {};
|
|
342
375
|
const result = {};
|
|
343
376
|
const assignValue = (val, key) => {
|
|
344
377
|
const targetKey = caseless && findKey(result, key) || key;
|
|
@@ -349,7 +382,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
349
382
|
} else if (isArray(val)) {
|
|
350
383
|
result[targetKey] = val.slice();
|
|
351
384
|
} else {
|
|
352
|
-
|
|
385
|
+
if (!skipUndefined || !isUndefined(val)) {
|
|
386
|
+
result[targetKey] = val;
|
|
387
|
+
}
|
|
353
388
|
}
|
|
354
389
|
};
|
|
355
390
|
|
|
@@ -371,7 +406,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
371
406
|
*/
|
|
372
407
|
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
|
373
408
|
forEach(b, (val, key) => {
|
|
374
|
-
if (thisArg && isFunction(val)) {
|
|
409
|
+
if (thisArg && isFunction$1(val)) {
|
|
375
410
|
a[key] = bind(val, thisArg);
|
|
376
411
|
} else {
|
|
377
412
|
a[key] = val;
|
|
@@ -511,13 +546,13 @@ const isTypedArray = (TypedArray => {
|
|
|
511
546
|
* @returns {void}
|
|
512
547
|
*/
|
|
513
548
|
const forEachEntry = (obj, fn) => {
|
|
514
|
-
const generator = obj && obj[
|
|
549
|
+
const generator = obj && obj[iterator];
|
|
515
550
|
|
|
516
|
-
const
|
|
551
|
+
const _iterator = generator.call(obj);
|
|
517
552
|
|
|
518
553
|
let result;
|
|
519
554
|
|
|
520
|
-
while ((result =
|
|
555
|
+
while ((result = _iterator.next()) && !result.done) {
|
|
521
556
|
const pair = result.value;
|
|
522
557
|
fn.call(obj, pair[0], pair[1]);
|
|
523
558
|
}
|
|
@@ -587,13 +622,13 @@ const reduceDescriptors = (obj, reducer) => {
|
|
|
587
622
|
const freezeMethods = (obj) => {
|
|
588
623
|
reduceDescriptors(obj, (descriptor, name) => {
|
|
589
624
|
// skip restricted props in strict mode
|
|
590
|
-
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
625
|
+
if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
591
626
|
return false;
|
|
592
627
|
}
|
|
593
628
|
|
|
594
629
|
const value = obj[name];
|
|
595
630
|
|
|
596
|
-
if (!isFunction(value)) return;
|
|
631
|
+
if (!isFunction$1(value)) return;
|
|
597
632
|
|
|
598
633
|
descriptor.enumerable = false;
|
|
599
634
|
|
|
@@ -630,25 +665,7 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
630
665
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
631
666
|
};
|
|
632
667
|
|
|
633
|
-
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|
634
|
-
|
|
635
|
-
const DIGIT = '0123456789';
|
|
636
668
|
|
|
637
|
-
const ALPHABET = {
|
|
638
|
-
DIGIT,
|
|
639
|
-
ALPHA,
|
|
640
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
641
|
-
};
|
|
642
|
-
|
|
643
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
644
|
-
let str = '';
|
|
645
|
-
const {length} = alphabet;
|
|
646
|
-
while (size--) {
|
|
647
|
-
str += alphabet[Math.random() * length|0];
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
return str;
|
|
651
|
-
};
|
|
652
669
|
|
|
653
670
|
/**
|
|
654
671
|
* If the thing is a FormData object, return true, otherwise return false.
|
|
@@ -658,7 +675,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
658
675
|
* @returns {boolean}
|
|
659
676
|
*/
|
|
660
677
|
function isSpecCompliantForm(thing) {
|
|
661
|
-
return !!(thing && isFunction(thing.append) && thing[
|
|
678
|
+
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|
662
679
|
}
|
|
663
680
|
|
|
664
681
|
const toJSONObject = (obj) => {
|
|
@@ -671,6 +688,11 @@ const toJSONObject = (obj) => {
|
|
|
671
688
|
return;
|
|
672
689
|
}
|
|
673
690
|
|
|
691
|
+
//Buffer check
|
|
692
|
+
if (isBuffer(source)) {
|
|
693
|
+
return source;
|
|
694
|
+
}
|
|
695
|
+
|
|
674
696
|
if(!('toJSON' in source)) {
|
|
675
697
|
stack[i] = source;
|
|
676
698
|
const target = isArray(source) ? [] : {};
|
|
@@ -695,7 +717,7 @@ const toJSONObject = (obj) => {
|
|
|
695
717
|
const isAsyncFn = kindOfTest('AsyncFunction');
|
|
696
718
|
|
|
697
719
|
const isThenable = (thing) =>
|
|
698
|
-
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
|
720
|
+
thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
699
721
|
|
|
700
722
|
// original code
|
|
701
723
|
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|
@@ -719,7 +741,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
719
741
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
720
742
|
})(
|
|
721
743
|
typeof setImmediate === 'function',
|
|
722
|
-
isFunction(_global.postMessage)
|
|
744
|
+
isFunction$1(_global.postMessage)
|
|
723
745
|
);
|
|
724
746
|
|
|
725
747
|
const asap = typeof queueMicrotask !== 'undefined' ?
|
|
@@ -727,6 +749,10 @@ const asap = typeof queueMicrotask !== 'undefined' ?
|
|
|
727
749
|
|
|
728
750
|
// *********************
|
|
729
751
|
|
|
752
|
+
|
|
753
|
+
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
754
|
+
|
|
755
|
+
|
|
730
756
|
const utils$1 = {
|
|
731
757
|
isArray,
|
|
732
758
|
isArrayBuffer,
|
|
@@ -738,6 +764,7 @@ const utils$1 = {
|
|
|
738
764
|
isBoolean,
|
|
739
765
|
isObject,
|
|
740
766
|
isPlainObject,
|
|
767
|
+
isEmptyObject,
|
|
741
768
|
isReadableStream,
|
|
742
769
|
isRequest,
|
|
743
770
|
isResponse,
|
|
@@ -747,7 +774,7 @@ const utils$1 = {
|
|
|
747
774
|
isFile,
|
|
748
775
|
isBlob,
|
|
749
776
|
isRegExp,
|
|
750
|
-
isFunction,
|
|
777
|
+
isFunction: isFunction$1,
|
|
751
778
|
isStream,
|
|
752
779
|
isURLSearchParams,
|
|
753
780
|
isTypedArray,
|
|
@@ -777,14 +804,13 @@ const utils$1 = {
|
|
|
777
804
|
findKey,
|
|
778
805
|
global: _global,
|
|
779
806
|
isContextDefined,
|
|
780
|
-
ALPHABET,
|
|
781
|
-
generateString,
|
|
782
807
|
isSpecCompliantForm,
|
|
783
808
|
toJSONObject,
|
|
784
809
|
isAsyncFn,
|
|
785
810
|
isThenable,
|
|
786
811
|
setImmediate: _setImmediate,
|
|
787
|
-
asap
|
|
812
|
+
asap,
|
|
813
|
+
isIterable
|
|
788
814
|
};
|
|
789
815
|
|
|
790
816
|
/**
|
|
@@ -874,11 +900,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
|
874
900
|
return prop !== 'isAxiosError';
|
|
875
901
|
});
|
|
876
902
|
|
|
877
|
-
|
|
903
|
+
const msg = error && error.message ? error.message : 'Error';
|
|
904
|
+
|
|
905
|
+
// Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
|
|
906
|
+
const errCode = code == null && error ? error.code : code;
|
|
907
|
+
AxiosError.call(axiosError, msg, errCode, config, request, response);
|
|
878
908
|
|
|
879
|
-
|
|
909
|
+
// Chain the original error on the standard field; non-enumerable to avoid JSON noise
|
|
910
|
+
if (error && axiosError.cause == null) {
|
|
911
|
+
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
|
|
912
|
+
}
|
|
880
913
|
|
|
881
|
-
axiosError.name = error.name;
|
|
914
|
+
axiosError.name = (error && error.name) || 'Error';
|
|
882
915
|
|
|
883
916
|
customProps && Object.assign(axiosError, customProps);
|
|
884
917
|
|
|
@@ -1000,6 +1033,10 @@ function toFormData(obj, formData, options) {
|
|
|
1000
1033
|
return value.toISOString();
|
|
1001
1034
|
}
|
|
1002
1035
|
|
|
1036
|
+
if (utils$1.isBoolean(value)) {
|
|
1037
|
+
return value.toString();
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1003
1040
|
if (!useBlob && utils$1.isBlob(value)) {
|
|
1004
1041
|
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
|
1005
1042
|
}
|
|
@@ -1162,9 +1199,7 @@ function encode(val) {
|
|
|
1162
1199
|
replace(/%3A/gi, ':').
|
|
1163
1200
|
replace(/%24/g, '$').
|
|
1164
1201
|
replace(/%2C/gi, ',').
|
|
1165
|
-
replace(/%20/g, '+')
|
|
1166
|
-
replace(/%5B/gi, '[').
|
|
1167
|
-
replace(/%5D/gi, ']');
|
|
1202
|
+
replace(/%20/g, '+');
|
|
1168
1203
|
}
|
|
1169
1204
|
|
|
1170
1205
|
/**
|
|
@@ -1290,6 +1325,29 @@ const transitionalDefaults = {
|
|
|
1290
1325
|
|
|
1291
1326
|
const URLSearchParams = url__default["default"].URLSearchParams;
|
|
1292
1327
|
|
|
1328
|
+
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|
1329
|
+
|
|
1330
|
+
const DIGIT = '0123456789';
|
|
1331
|
+
|
|
1332
|
+
const ALPHABET = {
|
|
1333
|
+
DIGIT,
|
|
1334
|
+
ALPHA,
|
|
1335
|
+
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
1336
|
+
};
|
|
1337
|
+
|
|
1338
|
+
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
1339
|
+
let str = '';
|
|
1340
|
+
const {length} = alphabet;
|
|
1341
|
+
const randomValues = new Uint32Array(size);
|
|
1342
|
+
crypto__default["default"].randomFillSync(randomValues);
|
|
1343
|
+
for (let i = 0; i < size; i++) {
|
|
1344
|
+
str += alphabet[randomValues[i] % length];
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
return str;
|
|
1348
|
+
};
|
|
1349
|
+
|
|
1350
|
+
|
|
1293
1351
|
const platform$1 = {
|
|
1294
1352
|
isNode: true,
|
|
1295
1353
|
classes: {
|
|
@@ -1297,6 +1355,8 @@ const platform$1 = {
|
|
|
1297
1355
|
FormData: FormData__default["default"],
|
|
1298
1356
|
Blob: typeof Blob !== 'undefined' && Blob || null
|
|
1299
1357
|
},
|
|
1358
|
+
ALPHABET,
|
|
1359
|
+
generateString,
|
|
1300
1360
|
protocols: [ 'http', 'https', 'file', 'data' ]
|
|
1301
1361
|
};
|
|
1302
1362
|
|
|
@@ -1359,7 +1419,7 @@ const platform = {
|
|
|
1359
1419
|
};
|
|
1360
1420
|
|
|
1361
1421
|
function toURLEncodedForm(data, options) {
|
|
1362
|
-
return toFormData(data, new platform.classes.URLSearchParams(),
|
|
1422
|
+
return toFormData(data, new platform.classes.URLSearchParams(), {
|
|
1363
1423
|
visitor: function(value, key, path, helpers) {
|
|
1364
1424
|
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
1365
1425
|
this.append(key, value.toString('base64'));
|
|
@@ -1367,8 +1427,9 @@ function toURLEncodedForm(data, options) {
|
|
|
1367
1427
|
}
|
|
1368
1428
|
|
|
1369
1429
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1430
|
+
},
|
|
1431
|
+
...options
|
|
1432
|
+
});
|
|
1372
1433
|
}
|
|
1373
1434
|
|
|
1374
1435
|
/**
|
|
@@ -1564,7 +1625,7 @@ const defaults = {
|
|
|
1564
1625
|
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1565
1626
|
|
|
1566
1627
|
try {
|
|
1567
|
-
return JSON.parse(data);
|
|
1628
|
+
return JSON.parse(data, this.parseReviver);
|
|
1568
1629
|
} catch (e) {
|
|
1569
1630
|
if (strictJSONParsing) {
|
|
1570
1631
|
if (e.name === 'SyntaxError') {
|
|
@@ -1762,10 +1823,18 @@ class AxiosHeaders {
|
|
|
1762
1823
|
setHeaders(header, valueOrRewrite);
|
|
1763
1824
|
} else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1764
1825
|
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1765
|
-
} else if (utils$1.
|
|
1766
|
-
|
|
1767
|
-
|
|
1826
|
+
} else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
|
|
1827
|
+
let obj = {}, dest, key;
|
|
1828
|
+
for (const entry of header) {
|
|
1829
|
+
if (!utils$1.isArray(entry)) {
|
|
1830
|
+
throw TypeError('Object iterator must return a key-value pair');
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
obj[key = entry[0]] = (dest = obj[key]) ?
|
|
1834
|
+
(utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]]) : entry[1];
|
|
1768
1835
|
}
|
|
1836
|
+
|
|
1837
|
+
setHeaders(obj, valueOrRewrite);
|
|
1769
1838
|
} else {
|
|
1770
1839
|
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1771
1840
|
}
|
|
@@ -1907,6 +1976,10 @@ class AxiosHeaders {
|
|
|
1907
1976
|
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
|
1908
1977
|
}
|
|
1909
1978
|
|
|
1979
|
+
getSetCookie() {
|
|
1980
|
+
return this.get("set-cookie") || [];
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1910
1983
|
get [Symbol.toStringTag]() {
|
|
1911
1984
|
return 'AxiosHeaders';
|
|
1912
1985
|
}
|
|
@@ -2071,14 +2144,15 @@ function combineURLs(baseURL, relativeURL) {
|
|
|
2071
2144
|
*
|
|
2072
2145
|
* @returns {string} The combined full path
|
|
2073
2146
|
*/
|
|
2074
|
-
function buildFullPath(baseURL, requestedURL) {
|
|
2075
|
-
|
|
2147
|
+
function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
|
|
2148
|
+
let isRelativeUrl = !isAbsoluteURL(requestedURL);
|
|
2149
|
+
if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
|
|
2076
2150
|
return combineURLs(baseURL, requestedURL);
|
|
2077
2151
|
}
|
|
2078
2152
|
return requestedURL;
|
|
2079
2153
|
}
|
|
2080
2154
|
|
|
2081
|
-
const VERSION = "1.
|
|
2155
|
+
const VERSION = "1.12.0";
|
|
2082
2156
|
|
|
2083
2157
|
function parseProtocol(url) {
|
|
2084
2158
|
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
|
@@ -2288,7 +2362,7 @@ const readBlob = async function* (blob) {
|
|
|
2288
2362
|
|
|
2289
2363
|
const readBlob$1 = readBlob;
|
|
2290
2364
|
|
|
2291
|
-
const BOUNDARY_ALPHABET =
|
|
2365
|
+
const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
|
|
2292
2366
|
|
|
2293
2367
|
const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new util__default["default"].TextEncoder();
|
|
2294
2368
|
|
|
@@ -2348,7 +2422,7 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2348
2422
|
const {
|
|
2349
2423
|
tag = 'form-data-boundary',
|
|
2350
2424
|
size = 25,
|
|
2351
|
-
boundary = tag + '-' +
|
|
2425
|
+
boundary = tag + '-' + platform.generateString(size, BOUNDARY_ALPHABET)
|
|
2352
2426
|
} = options || {};
|
|
2353
2427
|
|
|
2354
2428
|
if(!utils$1.isFormData(form)) {
|
|
@@ -2360,7 +2434,7 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2360
2434
|
}
|
|
2361
2435
|
|
|
2362
2436
|
const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
|
|
2363
|
-
const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF
|
|
2437
|
+
const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
|
|
2364
2438
|
let contentLength = footerBytes.byteLength;
|
|
2365
2439
|
|
|
2366
2440
|
const parts = Array.from(form.entries()).map(([name, value]) => {
|
|
@@ -2506,7 +2580,7 @@ function throttle(fn, freq) {
|
|
|
2506
2580
|
clearTimeout(timer);
|
|
2507
2581
|
timer = null;
|
|
2508
2582
|
}
|
|
2509
|
-
fn
|
|
2583
|
+
fn(...args);
|
|
2510
2584
|
};
|
|
2511
2585
|
|
|
2512
2586
|
const throttled = (...args) => {
|
|
@@ -2571,6 +2645,80 @@ const progressEventDecorator = (total, throttled) => {
|
|
|
2571
2645
|
|
|
2572
2646
|
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
|
2573
2647
|
|
|
2648
|
+
/**
|
|
2649
|
+
* Estimate decoded byte length of a data:// URL *without* allocating large buffers.
|
|
2650
|
+
* - For base64: compute exact decoded size using length and padding;
|
|
2651
|
+
* handle %XX at the character-count level (no string allocation).
|
|
2652
|
+
* - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
|
|
2653
|
+
*
|
|
2654
|
+
* @param {string} url
|
|
2655
|
+
* @returns {number}
|
|
2656
|
+
*/
|
|
2657
|
+
function estimateDataURLDecodedBytes(url) {
|
|
2658
|
+
if (!url || typeof url !== 'string') return 0;
|
|
2659
|
+
if (!url.startsWith('data:')) return 0;
|
|
2660
|
+
|
|
2661
|
+
const comma = url.indexOf(',');
|
|
2662
|
+
if (comma < 0) return 0;
|
|
2663
|
+
|
|
2664
|
+
const meta = url.slice(5, comma);
|
|
2665
|
+
const body = url.slice(comma + 1);
|
|
2666
|
+
const isBase64 = /;base64/i.test(meta);
|
|
2667
|
+
|
|
2668
|
+
if (isBase64) {
|
|
2669
|
+
let effectiveLen = body.length;
|
|
2670
|
+
const len = body.length; // cache length
|
|
2671
|
+
|
|
2672
|
+
for (let i = 0; i < len; i++) {
|
|
2673
|
+
if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
|
|
2674
|
+
const a = body.charCodeAt(i + 1);
|
|
2675
|
+
const b = body.charCodeAt(i + 2);
|
|
2676
|
+
const isHex =
|
|
2677
|
+
((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
|
|
2678
|
+
((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
|
|
2679
|
+
|
|
2680
|
+
if (isHex) {
|
|
2681
|
+
effectiveLen -= 2;
|
|
2682
|
+
i += 2;
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
let pad = 0;
|
|
2688
|
+
let idx = len - 1;
|
|
2689
|
+
|
|
2690
|
+
const tailIsPct3D = (j) =>
|
|
2691
|
+
j >= 2 &&
|
|
2692
|
+
body.charCodeAt(j - 2) === 37 && // '%'
|
|
2693
|
+
body.charCodeAt(j - 1) === 51 && // '3'
|
|
2694
|
+
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
|
|
2695
|
+
|
|
2696
|
+
if (idx >= 0) {
|
|
2697
|
+
if (body.charCodeAt(idx) === 61 /* '=' */) {
|
|
2698
|
+
pad++;
|
|
2699
|
+
idx--;
|
|
2700
|
+
} else if (tailIsPct3D(idx)) {
|
|
2701
|
+
pad++;
|
|
2702
|
+
idx -= 3;
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
if (pad === 1 && idx >= 0) {
|
|
2707
|
+
if (body.charCodeAt(idx) === 61 /* '=' */) {
|
|
2708
|
+
pad++;
|
|
2709
|
+
} else if (tailIsPct3D(idx)) {
|
|
2710
|
+
pad++;
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
const groups = Math.floor(effectiveLen / 4);
|
|
2715
|
+
const bytes = groups * 3 - (pad || 0);
|
|
2716
|
+
return bytes > 0 ? bytes : 0;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
return Buffer.byteLength(body, 'utf8');
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2574
2722
|
const zlibOptions = {
|
|
2575
2723
|
flush: zlib__default["default"].constants.Z_SYNC_FLUSH,
|
|
2576
2724
|
finishFlush: zlib__default["default"].constants.Z_SYNC_FLUSH
|
|
@@ -2591,6 +2739,7 @@ const supportedProtocols = platform.protocols.map(protocol => {
|
|
|
2591
2739
|
return protocol + ':';
|
|
2592
2740
|
});
|
|
2593
2741
|
|
|
2742
|
+
|
|
2594
2743
|
const flushOnFinish = (stream, [throttled, flush]) => {
|
|
2595
2744
|
stream
|
|
2596
2745
|
.on('end', flush)
|
|
@@ -2599,6 +2748,7 @@ const flushOnFinish = (stream, [throttled, flush]) => {
|
|
|
2599
2748
|
return throttled;
|
|
2600
2749
|
};
|
|
2601
2750
|
|
|
2751
|
+
|
|
2602
2752
|
/**
|
|
2603
2753
|
* If the proxy or config beforeRedirects functions are defined, call them with the options
|
|
2604
2754
|
* object.
|
|
@@ -2773,11 +2923,26 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
2773
2923
|
}
|
|
2774
2924
|
|
|
2775
2925
|
// Parse url
|
|
2776
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
2926
|
+
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
|
|
2777
2927
|
const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
|
|
2778
2928
|
const protocol = parsed.protocol || supportedProtocols[0];
|
|
2779
2929
|
|
|
2780
2930
|
if (protocol === 'data:') {
|
|
2931
|
+
// Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
|
|
2932
|
+
if (config.maxContentLength > -1) {
|
|
2933
|
+
// Use the exact string passed to fromDataURI (config.url); fall back to fullPath if needed.
|
|
2934
|
+
const dataUrl = String(config.url || fullPath || '');
|
|
2935
|
+
const estimated = estimateDataURLDecodedBytes(dataUrl);
|
|
2936
|
+
|
|
2937
|
+
if (estimated > config.maxContentLength) {
|
|
2938
|
+
return reject(new AxiosError(
|
|
2939
|
+
'maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
|
2940
|
+
AxiosError.ERR_BAD_RESPONSE,
|
|
2941
|
+
config
|
|
2942
|
+
));
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
|
|
2781
2946
|
let convertedData;
|
|
2782
2947
|
|
|
2783
2948
|
if (method !== 'GET') {
|
|
@@ -3380,7 +3545,7 @@ function mergeConfig(config1, config2) {
|
|
|
3380
3545
|
headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
|
|
3381
3546
|
};
|
|
3382
3547
|
|
|
3383
|
-
utils$1.forEach(Object.keys(
|
|
3548
|
+
utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
|
|
3384
3549
|
const merge = mergeMap[prop] || mergeDeepProperties;
|
|
3385
3550
|
const configValue = merge(config1[prop], config2[prop], prop);
|
|
3386
3551
|
(utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
@@ -3392,11 +3557,11 @@ function mergeConfig(config1, config2) {
|
|
|
3392
3557
|
const resolveConfig = (config) => {
|
|
3393
3558
|
const newConfig = mergeConfig({}, config);
|
|
3394
3559
|
|
|
3395
|
-
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
|
3560
|
+
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
3396
3561
|
|
|
3397
3562
|
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
|
3398
3563
|
|
|
3399
|
-
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
|
3564
|
+
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
|
|
3400
3565
|
|
|
3401
3566
|
// HTTP basic authentication
|
|
3402
3567
|
if (auth) {
|
|
@@ -3405,17 +3570,21 @@ const resolveConfig = (config) => {
|
|
|
3405
3570
|
);
|
|
3406
3571
|
}
|
|
3407
3572
|
|
|
3408
|
-
let contentType;
|
|
3409
|
-
|
|
3410
3573
|
if (utils$1.isFormData(data)) {
|
|
3411
3574
|
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
3412
|
-
headers.setContentType(undefined); //
|
|
3413
|
-
} else if ((
|
|
3414
|
-
//
|
|
3415
|
-
const
|
|
3416
|
-
headers
|
|
3575
|
+
headers.setContentType(undefined); // browser handles it
|
|
3576
|
+
} else if (utils$1.isFunction(data.getHeaders)) {
|
|
3577
|
+
// Node.js FormData (like form-data package)
|
|
3578
|
+
const formHeaders = data.getHeaders();
|
|
3579
|
+
// Only set safe headers to avoid overwriting security headers
|
|
3580
|
+
const allowedHeaders = ['content-type', 'content-length'];
|
|
3581
|
+
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
3582
|
+
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
3583
|
+
headers.set(key, val);
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3417
3586
|
}
|
|
3418
|
-
}
|
|
3587
|
+
}
|
|
3419
3588
|
|
|
3420
3589
|
// Add xsrf header
|
|
3421
3590
|
// This is only done if running in a standard browser environment.
|
|
@@ -3532,15 +3701,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
|
3532
3701
|
};
|
|
3533
3702
|
|
|
3534
3703
|
// Handle low level network errors
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3704
|
+
request.onerror = function handleError(event) {
|
|
3705
|
+
// Browsers deliver a ProgressEvent in XHR onerror
|
|
3706
|
+
// (message may be empty; when present, surface it)
|
|
3707
|
+
// See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
|
|
3708
|
+
const msg = event && event.message ? event.message : 'Network Error';
|
|
3709
|
+
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
|
3710
|
+
// attach the underlying event for consumers who want details
|
|
3711
|
+
err.event = event || null;
|
|
3712
|
+
reject(err);
|
|
3713
|
+
request = null;
|
|
3542
3714
|
};
|
|
3543
|
-
|
|
3715
|
+
|
|
3544
3716
|
// Handle timeout
|
|
3545
3717
|
request.ontimeout = function handleTimeout() {
|
|
3546
3718
|
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
@@ -3756,14 +3928,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
3756
3928
|
})
|
|
3757
3929
|
};
|
|
3758
3930
|
|
|
3759
|
-
const
|
|
3760
|
-
|
|
3931
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
3932
|
+
|
|
3933
|
+
const {isFunction} = utils$1;
|
|
3934
|
+
|
|
3935
|
+
const globalFetchAPI = (({fetch, Request, Response}) => ({
|
|
3936
|
+
fetch, Request, Response
|
|
3937
|
+
}))(utils$1.global);
|
|
3938
|
+
|
|
3939
|
+
const {
|
|
3940
|
+
ReadableStream: ReadableStream$1, TextEncoder: TextEncoder$1
|
|
3941
|
+
} = utils$1.global;
|
|
3761
3942
|
|
|
3762
|
-
// used only inside the fetch adapter
|
|
3763
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
3764
|
-
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
3765
|
-
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
|
3766
|
-
);
|
|
3767
3943
|
|
|
3768
3944
|
const test = (fn, ...args) => {
|
|
3769
3945
|
try {
|
|
@@ -3773,211 +3949,266 @@ const test = (fn, ...args) => {
|
|
|
3773
3949
|
}
|
|
3774
3950
|
};
|
|
3775
3951
|
|
|
3776
|
-
const
|
|
3777
|
-
|
|
3952
|
+
const factory = (env) => {
|
|
3953
|
+
const {fetch, Request, Response} = Object.assign({}, globalFetchAPI, env);
|
|
3954
|
+
const isFetchSupported = isFunction(fetch);
|
|
3955
|
+
const isRequestSupported = isFunction(Request);
|
|
3956
|
+
const isResponseSupported = isFunction(Response);
|
|
3778
3957
|
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
get duplex() {
|
|
3783
|
-
duplexAccessed = true;
|
|
3784
|
-
return 'half';
|
|
3785
|
-
},
|
|
3786
|
-
}).headers.has('Content-Type');
|
|
3958
|
+
if (!isFetchSupported) {
|
|
3959
|
+
return false;
|
|
3960
|
+
}
|
|
3787
3961
|
|
|
3788
|
-
|
|
3789
|
-
});
|
|
3962
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
|
|
3790
3963
|
|
|
3791
|
-
const
|
|
3964
|
+
const encodeText = isFetchSupported && (typeof TextEncoder$1 === 'function' ?
|
|
3965
|
+
((encoder) => (str) => encoder.encode(str))(new TextEncoder$1()) :
|
|
3966
|
+
async (str) => new Uint8Array(await new Request(str).arrayBuffer())
|
|
3967
|
+
);
|
|
3792
3968
|
|
|
3793
|
-
const
|
|
3794
|
-
|
|
3969
|
+
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
3970
|
+
let duplexAccessed = false;
|
|
3795
3971
|
|
|
3972
|
+
const hasContentType = new Request(platform.origin, {
|
|
3973
|
+
body: new ReadableStream$1(),
|
|
3974
|
+
method: 'POST',
|
|
3975
|
+
get duplex() {
|
|
3976
|
+
duplexAccessed = true;
|
|
3977
|
+
return 'half';
|
|
3978
|
+
},
|
|
3979
|
+
}).headers.has('Content-Type');
|
|
3796
3980
|
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3981
|
+
return duplexAccessed && !hasContentType;
|
|
3982
|
+
});
|
|
3983
|
+
|
|
3984
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
|
|
3985
|
+
test(() => utils$1.isReadableStream(new Response('').body));
|
|
3986
|
+
|
|
3987
|
+
const resolvers = {
|
|
3988
|
+
stream: supportsResponseStream && ((res) => res.body)
|
|
3989
|
+
};
|
|
3990
|
+
|
|
3991
|
+
isFetchSupported && ((() => {
|
|
3992
|
+
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
3993
|
+
!resolvers[type] && (resolvers[type] = (res, config) => {
|
|
3994
|
+
let method = res && res[type];
|
|
3995
|
+
|
|
3996
|
+
if (method) {
|
|
3997
|
+
return method.call(res);
|
|
3998
|
+
}
|
|
3800
3999
|
|
|
3801
|
-
isFetchSupported && (((res) => {
|
|
3802
|
-
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
3803
|
-
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
|
|
3804
|
-
(_, config) => {
|
|
3805
4000
|
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
3806
4001
|
});
|
|
3807
|
-
|
|
3808
|
-
})(
|
|
4002
|
+
});
|
|
4003
|
+
})());
|
|
3809
4004
|
|
|
3810
|
-
const getBodyLength = async (body) => {
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
4005
|
+
const getBodyLength = async (body) => {
|
|
4006
|
+
if (body == null) {
|
|
4007
|
+
return 0;
|
|
4008
|
+
}
|
|
3814
4009
|
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
4010
|
+
if (utils$1.isBlob(body)) {
|
|
4011
|
+
return body.size;
|
|
4012
|
+
}
|
|
3818
4013
|
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
4014
|
+
if (utils$1.isSpecCompliantForm(body)) {
|
|
4015
|
+
const _request = new Request(platform.origin, {
|
|
4016
|
+
method: 'POST',
|
|
4017
|
+
body,
|
|
4018
|
+
});
|
|
4019
|
+
return (await _request.arrayBuffer()).byteLength;
|
|
4020
|
+
}
|
|
3826
4021
|
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
4022
|
+
if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|
4023
|
+
return body.byteLength;
|
|
4024
|
+
}
|
|
3830
4025
|
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
4026
|
+
if (utils$1.isURLSearchParams(body)) {
|
|
4027
|
+
body = body + '';
|
|
4028
|
+
}
|
|
3834
4029
|
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
};
|
|
4030
|
+
if (utils$1.isString(body)) {
|
|
4031
|
+
return (await encodeText(body)).byteLength;
|
|
4032
|
+
}
|
|
4033
|
+
};
|
|
3839
4034
|
|
|
3840
|
-
const resolveBodyLength = async (headers, body) => {
|
|
3841
|
-
|
|
4035
|
+
const resolveBodyLength = async (headers, body) => {
|
|
4036
|
+
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|
3842
4037
|
|
|
3843
|
-
|
|
3844
|
-
};
|
|
4038
|
+
return length == null ? getBodyLength(body) : length;
|
|
4039
|
+
};
|
|
4040
|
+
|
|
4041
|
+
return async (config) => {
|
|
4042
|
+
let {
|
|
4043
|
+
url,
|
|
4044
|
+
method,
|
|
4045
|
+
data,
|
|
4046
|
+
signal,
|
|
4047
|
+
cancelToken,
|
|
4048
|
+
timeout,
|
|
4049
|
+
onDownloadProgress,
|
|
4050
|
+
onUploadProgress,
|
|
4051
|
+
responseType,
|
|
4052
|
+
headers,
|
|
4053
|
+
withCredentials = 'same-origin',
|
|
4054
|
+
fetchOptions
|
|
4055
|
+
} = resolveConfig(config);
|
|
4056
|
+
|
|
4057
|
+
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
4058
|
+
|
|
4059
|
+
let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
3845
4060
|
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
method,
|
|
3850
|
-
data,
|
|
3851
|
-
signal,
|
|
3852
|
-
cancelToken,
|
|
3853
|
-
timeout,
|
|
3854
|
-
onDownloadProgress,
|
|
3855
|
-
onUploadProgress,
|
|
3856
|
-
responseType,
|
|
3857
|
-
headers,
|
|
3858
|
-
withCredentials = 'same-origin',
|
|
3859
|
-
fetchOptions
|
|
3860
|
-
} = resolveConfig(config);
|
|
3861
|
-
|
|
3862
|
-
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
3863
|
-
|
|
3864
|
-
let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
3865
|
-
|
|
3866
|
-
let request;
|
|
3867
|
-
|
|
3868
|
-
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
4061
|
+
let request = null;
|
|
4062
|
+
|
|
4063
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
3869
4064
|
composedSignal.unsubscribe();
|
|
3870
|
-
|
|
4065
|
+
});
|
|
3871
4066
|
|
|
3872
|
-
|
|
4067
|
+
let requestContentLength;
|
|
3873
4068
|
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
4069
|
+
try {
|
|
4070
|
+
if (
|
|
4071
|
+
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
|
4072
|
+
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
|
4073
|
+
) {
|
|
4074
|
+
let _request = new Request(url, {
|
|
4075
|
+
method: 'POST',
|
|
4076
|
+
body: data,
|
|
4077
|
+
duplex: "half"
|
|
4078
|
+
});
|
|
3884
4079
|
|
|
3885
|
-
|
|
4080
|
+
let contentTypeHeader;
|
|
3886
4081
|
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
4082
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
|
4083
|
+
headers.setContentType(contentTypeHeader);
|
|
4084
|
+
}
|
|
3890
4085
|
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
4086
|
+
if (_request.body) {
|
|
4087
|
+
const [onProgress, flush] = progressEventDecorator(
|
|
4088
|
+
requestContentLength,
|
|
4089
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
4090
|
+
);
|
|
3896
4091
|
|
|
3897
|
-
|
|
4092
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
4093
|
+
}
|
|
3898
4094
|
}
|
|
3899
|
-
}
|
|
3900
4095
|
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
4096
|
+
if (!utils$1.isString(withCredentials)) {
|
|
4097
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
|
4098
|
+
}
|
|
3904
4099
|
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
request = new Request(url, {
|
|
3909
|
-
...fetchOptions,
|
|
3910
|
-
signal: composedSignal,
|
|
3911
|
-
method: method.toUpperCase(),
|
|
3912
|
-
headers: headers.normalize().toJSON(),
|
|
3913
|
-
body: data,
|
|
3914
|
-
duplex: "half",
|
|
3915
|
-
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
3916
|
-
});
|
|
4100
|
+
// Cloudflare Workers throws when credentials are defined
|
|
4101
|
+
// see https://github.com/cloudflare/workerd/issues/902
|
|
4102
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
3917
4103
|
|
|
3918
|
-
|
|
4104
|
+
const resolvedOptions = {
|
|
4105
|
+
...fetchOptions,
|
|
4106
|
+
signal: composedSignal,
|
|
4107
|
+
method: method.toUpperCase(),
|
|
4108
|
+
headers: headers.normalize().toJSON(),
|
|
4109
|
+
body: data,
|
|
4110
|
+
duplex: "half",
|
|
4111
|
+
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
4112
|
+
};
|
|
3919
4113
|
|
|
3920
|
-
|
|
4114
|
+
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
3921
4115
|
|
|
3922
|
-
|
|
3923
|
-
const options = {};
|
|
4116
|
+
let response = await (isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions));
|
|
3924
4117
|
|
|
3925
|
-
|
|
3926
|
-
options[prop] = response[prop];
|
|
3927
|
-
});
|
|
4118
|
+
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
|
3928
4119
|
|
|
3929
|
-
|
|
4120
|
+
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
|
4121
|
+
const options = {};
|
|
3930
4122
|
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
) || [];
|
|
4123
|
+
['status', 'statusText', 'headers'].forEach(prop => {
|
|
4124
|
+
options[prop] = response[prop];
|
|
4125
|
+
});
|
|
3935
4126
|
|
|
3936
|
-
|
|
3937
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
3938
|
-
flush && flush();
|
|
3939
|
-
unsubscribe && unsubscribe();
|
|
3940
|
-
}),
|
|
3941
|
-
options
|
|
3942
|
-
);
|
|
3943
|
-
}
|
|
4127
|
+
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|
3944
4128
|
|
|
3945
|
-
|
|
4129
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
4130
|
+
responseContentLength,
|
|
4131
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
4132
|
+
) || [];
|
|
3946
4133
|
|
|
3947
|
-
|
|
4134
|
+
response = new Response(
|
|
4135
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
4136
|
+
flush && flush();
|
|
4137
|
+
unsubscribe && unsubscribe();
|
|
4138
|
+
}),
|
|
4139
|
+
options
|
|
4140
|
+
);
|
|
4141
|
+
}
|
|
3948
4142
|
|
|
3949
|
-
|
|
4143
|
+
responseType = responseType || 'text';
|
|
3950
4144
|
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
4145
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
|
4146
|
+
|
|
4147
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
|
4148
|
+
|
|
4149
|
+
return await new Promise((resolve, reject) => {
|
|
4150
|
+
settle(resolve, reject, {
|
|
4151
|
+
data: responseData,
|
|
4152
|
+
headers: AxiosHeaders$1.from(response.headers),
|
|
4153
|
+
status: response.status,
|
|
4154
|
+
statusText: response.statusText,
|
|
4155
|
+
config,
|
|
4156
|
+
request
|
|
4157
|
+
});
|
|
4158
|
+
})
|
|
4159
|
+
} catch (err) {
|
|
4160
|
+
unsubscribe && unsubscribe();
|
|
4161
|
+
|
|
4162
|
+
if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
|
4163
|
+
throw Object.assign(
|
|
4164
|
+
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
|
4165
|
+
{
|
|
4166
|
+
cause: err.cause || err
|
|
4167
|
+
}
|
|
4168
|
+
)
|
|
4169
|
+
}
|
|
4170
|
+
|
|
4171
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
|
3971
4172
|
}
|
|
4173
|
+
}
|
|
4174
|
+
};
|
|
4175
|
+
|
|
4176
|
+
const seedCache = new Map();
|
|
4177
|
+
|
|
4178
|
+
const getFetch = (config) => {
|
|
4179
|
+
let env = utils$1.merge.call({
|
|
4180
|
+
skipUndefined: true
|
|
4181
|
+
}, globalFetchAPI, config ? config.env : null);
|
|
3972
4182
|
|
|
3973
|
-
|
|
4183
|
+
const {fetch, Request, Response} = env;
|
|
4184
|
+
|
|
4185
|
+
const seeds = [
|
|
4186
|
+
Request, Response, fetch
|
|
4187
|
+
];
|
|
4188
|
+
|
|
4189
|
+
let len = seeds.length, i = len,
|
|
4190
|
+
seed, target, map = seedCache;
|
|
4191
|
+
|
|
4192
|
+
while (i--) {
|
|
4193
|
+
seed = seeds[i];
|
|
4194
|
+
target = map.get(seed);
|
|
4195
|
+
|
|
4196
|
+
target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
|
|
4197
|
+
|
|
4198
|
+
map = target;
|
|
3974
4199
|
}
|
|
3975
|
-
|
|
4200
|
+
|
|
4201
|
+
return target;
|
|
4202
|
+
};
|
|
4203
|
+
|
|
4204
|
+
getFetch();
|
|
3976
4205
|
|
|
3977
4206
|
const knownAdapters = {
|
|
3978
4207
|
http: httpAdapter,
|
|
3979
4208
|
xhr: xhrAdapter,
|
|
3980
|
-
fetch:
|
|
4209
|
+
fetch: {
|
|
4210
|
+
get: getFetch,
|
|
4211
|
+
}
|
|
3981
4212
|
};
|
|
3982
4213
|
|
|
3983
4214
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
@@ -3996,7 +4227,7 @@ const renderReason = (reason) => `- ${reason}`;
|
|
|
3996
4227
|
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
3997
4228
|
|
|
3998
4229
|
const adapters = {
|
|
3999
|
-
getAdapter: (adapters) => {
|
|
4230
|
+
getAdapter: (adapters, config) => {
|
|
4000
4231
|
adapters = utils$1.isArray(adapters) ? adapters : [adapters];
|
|
4001
4232
|
|
|
4002
4233
|
const {length} = adapters;
|
|
@@ -4019,7 +4250,7 @@ const adapters = {
|
|
|
4019
4250
|
}
|
|
4020
4251
|
}
|
|
4021
4252
|
|
|
4022
|
-
if (adapter) {
|
|
4253
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
|
4023
4254
|
break;
|
|
4024
4255
|
}
|
|
4025
4256
|
|
|
@@ -4087,7 +4318,7 @@ function dispatchRequest(config) {
|
|
|
4087
4318
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
4088
4319
|
}
|
|
4089
4320
|
|
|
4090
|
-
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
|
|
4321
|
+
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
|
|
4091
4322
|
|
|
4092
4323
|
return adapter(config).then(function onAdapterResolution(response) {
|
|
4093
4324
|
throwIfCancellationRequested(config);
|
|
@@ -4227,7 +4458,7 @@ const validators = validator.validators;
|
|
|
4227
4458
|
*/
|
|
4228
4459
|
class Axios {
|
|
4229
4460
|
constructor(instanceConfig) {
|
|
4230
|
-
this.defaults = instanceConfig;
|
|
4461
|
+
this.defaults = instanceConfig || {};
|
|
4231
4462
|
this.interceptors = {
|
|
4232
4463
|
request: new InterceptorManager$1(),
|
|
4233
4464
|
response: new InterceptorManager$1()
|
|
@@ -4304,6 +4535,13 @@ class Axios {
|
|
|
4304
4535
|
}
|
|
4305
4536
|
}
|
|
4306
4537
|
|
|
4538
|
+
// Set config.allowAbsoluteUrls
|
|
4539
|
+
if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
|
|
4540
|
+
config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
|
|
4541
|
+
} else {
|
|
4542
|
+
config.allowAbsoluteUrls = true;
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4307
4545
|
validator.assertOptions(config, {
|
|
4308
4546
|
baseUrl: validators.spelling('baseURL'),
|
|
4309
4547
|
withXsrfToken: validators.spelling('withXSRFToken')
|
|
@@ -4351,8 +4589,8 @@ class Axios {
|
|
|
4351
4589
|
|
|
4352
4590
|
if (!synchronousRequestInterceptors) {
|
|
4353
4591
|
const chain = [dispatchRequest.bind(this), undefined];
|
|
4354
|
-
chain.unshift
|
|
4355
|
-
chain.push
|
|
4592
|
+
chain.unshift(...requestInterceptorChain);
|
|
4593
|
+
chain.push(...responseInterceptorChain);
|
|
4356
4594
|
len = chain.length;
|
|
4357
4595
|
|
|
4358
4596
|
promise = Promise.resolve(config);
|
|
@@ -4399,7 +4637,7 @@ class Axios {
|
|
|
4399
4637
|
|
|
4400
4638
|
getUri(config) {
|
|
4401
4639
|
config = mergeConfig(this.defaults, config);
|
|
4402
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
4640
|
+
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
|
|
4403
4641
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
4404
4642
|
}
|
|
4405
4643
|
}
|