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.
@@ -1,4 +1,4 @@
1
- // Axios v1.7.9 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ /*! Axios v1.12.0 Copyright (c) 2025 Matt Zabriskie and contributors */
2
2
  'use strict';
3
3
 
4
4
  function bind(fn, thisArg) {
@@ -11,6 +11,7 @@ function bind(fn, thisArg) {
11
11
 
12
12
  const {toString} = Object.prototype;
13
13
  const {getPrototypeOf} = Object;
14
+ const {iterator, toStringTag} = Symbol;
14
15
 
15
16
  const kindOf = (cache => thing => {
16
17
  const str = toString.call(thing);
@@ -51,7 +52,7 @@ const isUndefined = typeOfTest('undefined');
51
52
  */
52
53
  function isBuffer(val) {
53
54
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
54
- && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
55
+ && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
55
56
  }
56
57
 
57
58
  /**
@@ -96,7 +97,7 @@ const isString = typeOfTest('string');
96
97
  * @param {*} val The value to test
97
98
  * @returns {boolean} True if value is a Function, otherwise false
98
99
  */
99
- const isFunction = typeOfTest('function');
100
+ const isFunction$1 = typeOfTest('function');
100
101
 
101
102
  /**
102
103
  * Determine if a value is a Number
@@ -137,7 +138,28 @@ const isPlainObject = (val) => {
137
138
  }
138
139
 
139
140
  const prototype = getPrototypeOf(val);
140
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
141
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
142
+ };
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
+ }
141
163
  };
142
164
 
143
165
  /**
@@ -183,7 +205,7 @@ const isFileList = kindOfTest('FileList');
183
205
  *
184
206
  * @returns {boolean} True if value is a Stream, otherwise false
185
207
  */
186
- const isStream = (val) => isObject(val) && isFunction(val.pipe);
208
+ const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
187
209
 
188
210
  /**
189
211
  * Determine if a value is a FormData
@@ -196,10 +218,10 @@ const isFormData = (thing) => {
196
218
  let kind;
197
219
  return thing && (
198
220
  (typeof FormData === 'function' && thing instanceof FormData) || (
199
- isFunction(thing.append) && (
221
+ isFunction$1(thing.append) && (
200
222
  (kind = kindOf(thing)) === 'formdata' ||
201
223
  // detect form-data instance
202
- (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
224
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
203
225
  )
204
226
  )
205
227
  )
@@ -262,6 +284,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
262
284
  fn.call(null, obj[i], i, obj);
263
285
  }
264
286
  } else {
287
+ // Buffer check
288
+ if (isBuffer(obj)) {
289
+ return;
290
+ }
291
+
265
292
  // Iterate over object keys
266
293
  const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
267
294
  const len = keys.length;
@@ -275,6 +302,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
275
302
  }
276
303
 
277
304
  function findKey(obj, key) {
305
+ if (isBuffer(obj)){
306
+ return null;
307
+ }
308
+
278
309
  key = key.toLowerCase();
279
310
  const keys = Object.keys(obj);
280
311
  let i = keys.length;
@@ -315,7 +346,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
315
346
  * @returns {Object} Result of all merge properties
316
347
  */
317
348
  function merge(/* obj1, obj2, obj3, ... */) {
318
- const {caseless} = isContextDefined(this) && this || {};
349
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
319
350
  const result = {};
320
351
  const assignValue = (val, key) => {
321
352
  const targetKey = caseless && findKey(result, key) || key;
@@ -326,7 +357,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
326
357
  } else if (isArray(val)) {
327
358
  result[targetKey] = val.slice();
328
359
  } else {
329
- result[targetKey] = val;
360
+ if (!skipUndefined || !isUndefined(val)) {
361
+ result[targetKey] = val;
362
+ }
330
363
  }
331
364
  };
332
365
 
@@ -348,7 +381,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
348
381
  */
349
382
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
350
383
  forEach(b, (val, key) => {
351
- if (thisArg && isFunction(val)) {
384
+ if (thisArg && isFunction$1(val)) {
352
385
  a[key] = bind(val, thisArg);
353
386
  } else {
354
387
  a[key] = val;
@@ -488,13 +521,13 @@ const isTypedArray = (TypedArray => {
488
521
  * @returns {void}
489
522
  */
490
523
  const forEachEntry = (obj, fn) => {
491
- const generator = obj && obj[Symbol.iterator];
524
+ const generator = obj && obj[iterator];
492
525
 
493
- const iterator = generator.call(obj);
526
+ const _iterator = generator.call(obj);
494
527
 
495
528
  let result;
496
529
 
497
- while ((result = iterator.next()) && !result.done) {
530
+ while ((result = _iterator.next()) && !result.done) {
498
531
  const pair = result.value;
499
532
  fn.call(obj, pair[0], pair[1]);
500
533
  }
@@ -564,13 +597,13 @@ const reduceDescriptors = (obj, reducer) => {
564
597
  const freezeMethods = (obj) => {
565
598
  reduceDescriptors(obj, (descriptor, name) => {
566
599
  // skip restricted props in strict mode
567
- if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
600
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
568
601
  return false;
569
602
  }
570
603
 
571
604
  const value = obj[name];
572
605
 
573
- if (!isFunction(value)) return;
606
+ if (!isFunction$1(value)) return;
574
607
 
575
608
  descriptor.enumerable = false;
576
609
 
@@ -607,25 +640,7 @@ const toFiniteNumber = (value, defaultValue) => {
607
640
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
608
641
  };
609
642
 
610
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
611
643
 
612
- const DIGIT = '0123456789';
613
-
614
- const ALPHABET = {
615
- DIGIT,
616
- ALPHA,
617
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
618
- };
619
-
620
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
621
- let str = '';
622
- const {length} = alphabet;
623
- while (size--) {
624
- str += alphabet[Math.random() * length|0];
625
- }
626
-
627
- return str;
628
- };
629
644
 
630
645
  /**
631
646
  * If the thing is a FormData object, return true, otherwise return false.
@@ -635,7 +650,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
635
650
  * @returns {boolean}
636
651
  */
637
652
  function isSpecCompliantForm(thing) {
638
- return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
653
+ return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
639
654
  }
640
655
 
641
656
  const toJSONObject = (obj) => {
@@ -648,6 +663,11 @@ const toJSONObject = (obj) => {
648
663
  return;
649
664
  }
650
665
 
666
+ //Buffer check
667
+ if (isBuffer(source)) {
668
+ return source;
669
+ }
670
+
651
671
  if(!('toJSON' in source)) {
652
672
  stack[i] = source;
653
673
  const target = isArray(source) ? [] : {};
@@ -672,7 +692,7 @@ const toJSONObject = (obj) => {
672
692
  const isAsyncFn = kindOfTest('AsyncFunction');
673
693
 
674
694
  const isThenable = (thing) =>
675
- 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);
676
696
 
677
697
  // original code
678
698
  // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
@@ -696,7 +716,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
696
716
  })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
697
717
  })(
698
718
  typeof setImmediate === 'function',
699
- isFunction(_global.postMessage)
719
+ isFunction$1(_global.postMessage)
700
720
  );
701
721
 
702
722
  const asap = typeof queueMicrotask !== 'undefined' ?
@@ -704,6 +724,10 @@ const asap = typeof queueMicrotask !== 'undefined' ?
704
724
 
705
725
  // *********************
706
726
 
727
+
728
+ const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
729
+
730
+
707
731
  var utils$1 = {
708
732
  isArray,
709
733
  isArrayBuffer,
@@ -715,6 +739,7 @@ var utils$1 = {
715
739
  isBoolean,
716
740
  isObject,
717
741
  isPlainObject,
742
+ isEmptyObject,
718
743
  isReadableStream,
719
744
  isRequest,
720
745
  isResponse,
@@ -724,7 +749,7 @@ var utils$1 = {
724
749
  isFile,
725
750
  isBlob,
726
751
  isRegExp,
727
- isFunction,
752
+ isFunction: isFunction$1,
728
753
  isStream,
729
754
  isURLSearchParams,
730
755
  isTypedArray,
@@ -754,14 +779,13 @@ var utils$1 = {
754
779
  findKey,
755
780
  global: _global,
756
781
  isContextDefined,
757
- ALPHABET,
758
- generateString,
759
782
  isSpecCompliantForm,
760
783
  toJSONObject,
761
784
  isAsyncFn,
762
785
  isThenable,
763
786
  setImmediate: _setImmediate,
764
- asap
787
+ asap,
788
+ isIterable
765
789
  };
766
790
 
767
791
  /**
@@ -851,11 +875,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
851
875
  return prop !== 'isAxiosError';
852
876
  });
853
877
 
854
- AxiosError.call(axiosError, error.message, code, config, request, response);
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);
855
883
 
856
- axiosError.cause = error;
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
+ }
857
888
 
858
- axiosError.name = error.name;
889
+ axiosError.name = (error && error.name) || 'Error';
859
890
 
860
891
  customProps && Object.assign(axiosError, customProps);
861
892
 
@@ -980,6 +1011,10 @@ function toFormData(obj, formData, options) {
980
1011
  return value.toISOString();
981
1012
  }
982
1013
 
1014
+ if (utils$1.isBoolean(value)) {
1015
+ return value.toString();
1016
+ }
1017
+
983
1018
  if (!useBlob && utils$1.isBlob(value)) {
984
1019
  throw new AxiosError('Blob is not supported. Use a Buffer instead.');
985
1020
  }
@@ -1142,9 +1177,7 @@ function encode(val) {
1142
1177
  replace(/%3A/gi, ':').
1143
1178
  replace(/%24/g, '$').
1144
1179
  replace(/%2C/gi, ',').
1145
- replace(/%20/g, '+').
1146
- replace(/%5B/gi, '[').
1147
- replace(/%5D/gi, ']');
1180
+ replace(/%20/g, '+');
1148
1181
  }
1149
1182
 
1150
1183
  /**
@@ -1343,7 +1376,7 @@ var platform = {
1343
1376
  };
1344
1377
 
1345
1378
  function toURLEncodedForm(data, options) {
1346
- return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
1379
+ return toFormData(data, new platform.classes.URLSearchParams(), {
1347
1380
  visitor: function(value, key, path, helpers) {
1348
1381
  if (platform.isNode && utils$1.isBuffer(value)) {
1349
1382
  this.append(key, value.toString('base64'));
@@ -1351,8 +1384,9 @@ function toURLEncodedForm(data, options) {
1351
1384
  }
1352
1385
 
1353
1386
  return helpers.defaultVisitor.apply(this, arguments);
1354
- }
1355
- }, options));
1387
+ },
1388
+ ...options
1389
+ });
1356
1390
  }
1357
1391
 
1358
1392
  /**
@@ -1548,7 +1582,7 @@ const defaults = {
1548
1582
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
1549
1583
 
1550
1584
  try {
1551
- return JSON.parse(data);
1585
+ return JSON.parse(data, this.parseReviver);
1552
1586
  } catch (e) {
1553
1587
  if (strictJSONParsing) {
1554
1588
  if (e.name === 'SyntaxError') {
@@ -1746,10 +1780,18 @@ class AxiosHeaders {
1746
1780
  setHeaders(header, valueOrRewrite);
1747
1781
  } else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1748
1782
  setHeaders(parseHeaders(header), valueOrRewrite);
1749
- } else if (utils$1.isHeaders(header)) {
1750
- for (const [key, value] of header.entries()) {
1751
- setHeader(value, key, rewrite);
1783
+ } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
1784
+ let obj = {}, dest, key;
1785
+ for (const entry of header) {
1786
+ if (!utils$1.isArray(entry)) {
1787
+ throw TypeError('Object iterator must return a key-value pair');
1788
+ }
1789
+
1790
+ obj[key = entry[0]] = (dest = obj[key]) ?
1791
+ (utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]]) : entry[1];
1752
1792
  }
1793
+
1794
+ setHeaders(obj, valueOrRewrite);
1753
1795
  } else {
1754
1796
  header != null && setHeader(valueOrRewrite, header, rewrite);
1755
1797
  }
@@ -1891,6 +1933,10 @@ class AxiosHeaders {
1891
1933
  return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
1892
1934
  }
1893
1935
 
1936
+ getSetCookie() {
1937
+ return this.get("set-cookie") || [];
1938
+ }
1939
+
1894
1940
  get [Symbol.toStringTag]() {
1895
1941
  return 'AxiosHeaders';
1896
1942
  }
@@ -2093,7 +2139,7 @@ function throttle(fn, freq) {
2093
2139
  clearTimeout(timer);
2094
2140
  timer = null;
2095
2141
  }
2096
- fn.apply(null, args);
2142
+ fn(...args);
2097
2143
  };
2098
2144
 
2099
2145
  const throttled = (...args) => {
@@ -2248,8 +2294,9 @@ function combineURLs(baseURL, relativeURL) {
2248
2294
  *
2249
2295
  * @returns {string} The combined full path
2250
2296
  */
2251
- function buildFullPath(baseURL, requestedURL) {
2252
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2297
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2298
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2299
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
2253
2300
  return combineURLs(baseURL, requestedURL);
2254
2301
  }
2255
2302
  return requestedURL;
@@ -2348,7 +2395,7 @@ function mergeConfig(config1, config2) {
2348
2395
  headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2349
2396
  };
2350
2397
 
2351
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2398
+ utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
2352
2399
  const merge = mergeMap[prop] || mergeDeepProperties;
2353
2400
  const configValue = merge(config1[prop], config2[prop], prop);
2354
2401
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
@@ -2360,11 +2407,11 @@ function mergeConfig(config1, config2) {
2360
2407
  var resolveConfig = (config) => {
2361
2408
  const newConfig = mergeConfig({}, config);
2362
2409
 
2363
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2410
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
2364
2411
 
2365
2412
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
2366
2413
 
2367
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2414
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2368
2415
 
2369
2416
  // HTTP basic authentication
2370
2417
  if (auth) {
@@ -2373,17 +2420,21 @@ var resolveConfig = (config) => {
2373
2420
  );
2374
2421
  }
2375
2422
 
2376
- let contentType;
2377
-
2378
2423
  if (utils$1.isFormData(data)) {
2379
2424
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2380
- headers.setContentType(undefined); // Let the browser set it
2381
- } else if ((contentType = headers.getContentType()) !== false) {
2382
- // fix semicolon duplication issue for ReactNative FormData implementation
2383
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2384
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
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
+ });
2385
2436
  }
2386
- }
2437
+ }
2387
2438
 
2388
2439
  // Add xsrf header
2389
2440
  // This is only done if running in a standard browser environment.
@@ -2500,15 +2551,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2500
2551
  };
2501
2552
 
2502
2553
  // Handle low level network errors
2503
- request.onerror = function handleError() {
2504
- // Real errors are hidden from us by the browser
2505
- // onerror should only fire if it's a network error
2506
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2507
-
2508
- // Clean up request
2509
- request = null;
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;
2510
2564
  };
2511
-
2565
+
2512
2566
  // Handle timeout
2513
2567
  request.ontimeout = function handleTimeout() {
2514
2568
  let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
@@ -2724,14 +2778,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2724
2778
  })
2725
2779
  };
2726
2780
 
2727
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
2728
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
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;
2729
2792
 
2730
- // used only inside the fetch adapter
2731
- const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2732
- ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2733
- async (str) => new Uint8Array(await new Response(str).arrayBuffer())
2734
- );
2735
2793
 
2736
2794
  const test = (fn, ...args) => {
2737
2795
  try {
@@ -2741,211 +2799,266 @@ const test = (fn, ...args) => {
2741
2799
  }
2742
2800
  };
2743
2801
 
2744
- const supportsRequestStream = isReadableStreamSupported && test(() => {
2745
- let duplexAccessed = false;
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);
2746
2807
 
2747
- const hasContentType = new Request(platform.origin, {
2748
- body: new ReadableStream(),
2749
- method: 'POST',
2750
- get duplex() {
2751
- duplexAccessed = true;
2752
- return 'half';
2753
- },
2754
- }).headers.has('Content-Type');
2808
+ if (!isFetchSupported) {
2809
+ return false;
2810
+ }
2755
2811
 
2756
- return duplexAccessed && !hasContentType;
2757
- });
2812
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
2758
2813
 
2759
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
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
+ );
2760
2818
 
2761
- const supportsResponseStream = isReadableStreamSupported &&
2762
- test(() => utils$1.isReadableStream(new Response('').body));
2819
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
2820
+ let duplexAccessed = false;
2763
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');
2764
2830
 
2765
- const resolvers = {
2766
- stream: supportsResponseStream && ((res) => res.body)
2767
- };
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
+ }
2768
2849
 
2769
- isFetchSupported && (((res) => {
2770
- ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2771
- !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2772
- (_, config) => {
2773
2850
  throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2774
2851
  });
2775
- });
2776
- })(new Response));
2852
+ });
2853
+ })());
2777
2854
 
2778
- const getBodyLength = async (body) => {
2779
- if (body == null) {
2780
- return 0;
2781
- }
2855
+ const getBodyLength = async (body) => {
2856
+ if (body == null) {
2857
+ return 0;
2858
+ }
2782
2859
 
2783
- if(utils$1.isBlob(body)) {
2784
- return body.size;
2785
- }
2860
+ if (utils$1.isBlob(body)) {
2861
+ return body.size;
2862
+ }
2786
2863
 
2787
- if(utils$1.isSpecCompliantForm(body)) {
2788
- const _request = new Request(platform.origin, {
2789
- method: 'POST',
2790
- body,
2791
- });
2792
- return (await _request.arrayBuffer()).byteLength;
2793
- }
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
+ }
2794
2871
 
2795
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2796
- return body.byteLength;
2797
- }
2872
+ if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2873
+ return body.byteLength;
2874
+ }
2798
2875
 
2799
- if(utils$1.isURLSearchParams(body)) {
2800
- body = body + '';
2801
- }
2876
+ if (utils$1.isURLSearchParams(body)) {
2877
+ body = body + '';
2878
+ }
2802
2879
 
2803
- if(utils$1.isString(body)) {
2804
- return (await encodeText(body)).byteLength;
2805
- }
2806
- };
2880
+ if (utils$1.isString(body)) {
2881
+ return (await encodeText(body)).byteLength;
2882
+ }
2883
+ };
2807
2884
 
2808
- const resolveBodyLength = async (headers, body) => {
2809
- const length = utils$1.toFiniteNumber(headers.getContentLength());
2885
+ const resolveBodyLength = async (headers, body) => {
2886
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
2810
2887
 
2811
- return length == null ? getBodyLength(body) : length;
2812
- };
2888
+ return length == null ? getBodyLength(body) : length;
2889
+ };
2890
+
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;
2813
2912
 
2814
- var fetchAdapter = isFetchSupported && (async (config) => {
2815
- let {
2816
- url,
2817
- method,
2818
- data,
2819
- signal,
2820
- cancelToken,
2821
- timeout,
2822
- onDownloadProgress,
2823
- onUploadProgress,
2824
- responseType,
2825
- headers,
2826
- withCredentials = 'same-origin',
2827
- fetchOptions
2828
- } = resolveConfig(config);
2829
-
2830
- responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2831
-
2832
- let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2833
-
2834
- let request;
2835
-
2836
- const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2913
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2837
2914
  composedSignal.unsubscribe();
2838
- });
2915
+ });
2839
2916
 
2840
- let requestContentLength;
2917
+ let requestContentLength;
2841
2918
 
2842
- try {
2843
- if (
2844
- onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2845
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2846
- ) {
2847
- let _request = new Request(url, {
2848
- method: 'POST',
2849
- body: data,
2850
- duplex: "half"
2851
- });
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
+ });
2852
2929
 
2853
- let contentTypeHeader;
2930
+ let contentTypeHeader;
2854
2931
 
2855
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2856
- headers.setContentType(contentTypeHeader);
2857
- }
2932
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2933
+ headers.setContentType(contentTypeHeader);
2934
+ }
2858
2935
 
2859
- if (_request.body) {
2860
- const [onProgress, flush] = progressEventDecorator(
2861
- requestContentLength,
2862
- progressEventReducer(asyncDecorator(onUploadProgress))
2863
- );
2936
+ if (_request.body) {
2937
+ const [onProgress, flush] = progressEventDecorator(
2938
+ requestContentLength,
2939
+ progressEventReducer(asyncDecorator(onUploadProgress))
2940
+ );
2864
2941
 
2865
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2942
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2943
+ }
2866
2944
  }
2867
- }
2868
2945
 
2869
- if (!utils$1.isString(withCredentials)) {
2870
- withCredentials = withCredentials ? 'include' : 'omit';
2871
- }
2946
+ if (!utils$1.isString(withCredentials)) {
2947
+ withCredentials = withCredentials ? 'include' : 'omit';
2948
+ }
2872
2949
 
2873
- // Cloudflare Workers throws when credentials are defined
2874
- // see https://github.com/cloudflare/workerd/issues/902
2875
- const isCredentialsSupported = "credentials" in Request.prototype;
2876
- request = new Request(url, {
2877
- ...fetchOptions,
2878
- signal: composedSignal,
2879
- method: method.toUpperCase(),
2880
- headers: headers.normalize().toJSON(),
2881
- body: data,
2882
- duplex: "half",
2883
- credentials: isCredentialsSupported ? withCredentials : undefined
2884
- });
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;
2885
2953
 
2886
- let response = await fetch(request);
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
+ };
2887
2963
 
2888
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2964
+ request = isRequestSupported && new Request(url, resolvedOptions);
2889
2965
 
2890
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2891
- const options = {};
2966
+ let response = await (isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions));
2892
2967
 
2893
- ['status', 'statusText', 'headers'].forEach(prop => {
2894
- options[prop] = response[prop];
2895
- });
2968
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2896
2969
 
2897
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2970
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2971
+ const options = {};
2898
2972
 
2899
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2900
- responseContentLength,
2901
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
2902
- ) || [];
2973
+ ['status', 'statusText', 'headers'].forEach(prop => {
2974
+ options[prop] = response[prop];
2975
+ });
2903
2976
 
2904
- response = new Response(
2905
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2906
- flush && flush();
2907
- unsubscribe && unsubscribe();
2908
- }),
2909
- options
2910
- );
2911
- }
2977
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2912
2978
 
2913
- responseType = responseType || 'text';
2979
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2980
+ responseContentLength,
2981
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
2982
+ ) || [];
2914
2983
 
2915
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2984
+ response = new Response(
2985
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2986
+ flush && flush();
2987
+ unsubscribe && unsubscribe();
2988
+ }),
2989
+ options
2990
+ );
2991
+ }
2916
2992
 
2917
- !isStreamResponse && unsubscribe && unsubscribe();
2993
+ responseType = responseType || 'text';
2918
2994
 
2919
- return await new Promise((resolve, reject) => {
2920
- settle(resolve, reject, {
2921
- data: responseData,
2922
- headers: AxiosHeaders$1.from(response.headers),
2923
- status: response.status,
2924
- statusText: response.statusText,
2925
- config,
2926
- request
2927
- });
2928
- })
2929
- } catch (err) {
2930
- unsubscribe && unsubscribe();
2931
-
2932
- if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2933
- throw Object.assign(
2934
- new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
2935
- {
2936
- cause: err.cause || err
2937
- }
2938
- )
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);
2939
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
+ ];
3038
+
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);
2940
3045
 
2941
- throw AxiosError.from(err, err && err.code, config, request);
3046
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
3047
+
3048
+ map = target;
2942
3049
  }
2943
- });
3050
+
3051
+ return target;
3052
+ };
3053
+
3054
+ getFetch();
2944
3055
 
2945
3056
  const knownAdapters = {
2946
3057
  http: httpAdapter,
2947
3058
  xhr: xhrAdapter,
2948
- fetch: fetchAdapter
3059
+ fetch: {
3060
+ get: getFetch,
3061
+ }
2949
3062
  };
2950
3063
 
2951
3064
  utils$1.forEach(knownAdapters, (fn, value) => {
@@ -2964,7 +3077,7 @@ const renderReason = (reason) => `- ${reason}`;
2964
3077
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
2965
3078
 
2966
3079
  var adapters = {
2967
- getAdapter: (adapters) => {
3080
+ getAdapter: (adapters, config) => {
2968
3081
  adapters = utils$1.isArray(adapters) ? adapters : [adapters];
2969
3082
 
2970
3083
  const {length} = adapters;
@@ -2987,7 +3100,7 @@ var adapters = {
2987
3100
  }
2988
3101
  }
2989
3102
 
2990
- if (adapter) {
3103
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
2991
3104
  break;
2992
3105
  }
2993
3106
 
@@ -3055,7 +3168,7 @@ function dispatchRequest(config) {
3055
3168
  config.headers.setContentType('application/x-www-form-urlencoded', false);
3056
3169
  }
3057
3170
 
3058
- const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3171
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
3059
3172
 
3060
3173
  return adapter(config).then(function onAdapterResolution(response) {
3061
3174
  throwIfCancellationRequested(config);
@@ -3089,7 +3202,7 @@ function dispatchRequest(config) {
3089
3202
  });
3090
3203
  }
3091
3204
 
3092
- const VERSION = "1.7.9";
3205
+ const VERSION = "1.12.0";
3093
3206
 
3094
3207
  const validators$1 = {};
3095
3208
 
@@ -3197,7 +3310,7 @@ const validators = validator.validators;
3197
3310
  */
3198
3311
  class Axios {
3199
3312
  constructor(instanceConfig) {
3200
- this.defaults = instanceConfig;
3313
+ this.defaults = instanceConfig || {};
3201
3314
  this.interceptors = {
3202
3315
  request: new InterceptorManager$1(),
3203
3316
  response: new InterceptorManager$1()
@@ -3274,6 +3387,13 @@ class Axios {
3274
3387
  }
3275
3388
  }
3276
3389
 
3390
+ // Set config.allowAbsoluteUrls
3391
+ if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
3392
+ config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
3393
+ } else {
3394
+ config.allowAbsoluteUrls = true;
3395
+ }
3396
+
3277
3397
  validator.assertOptions(config, {
3278
3398
  baseUrl: validators.spelling('baseURL'),
3279
3399
  withXsrfToken: validators.spelling('withXSRFToken')
@@ -3321,8 +3441,8 @@ class Axios {
3321
3441
 
3322
3442
  if (!synchronousRequestInterceptors) {
3323
3443
  const chain = [dispatchRequest.bind(this), undefined];
3324
- chain.unshift.apply(chain, requestInterceptorChain);
3325
- chain.push.apply(chain, responseInterceptorChain);
3444
+ chain.unshift(...requestInterceptorChain);
3445
+ chain.push(...responseInterceptorChain);
3326
3446
  len = chain.length;
3327
3447
 
3328
3448
  promise = Promise.resolve(config);
@@ -3369,7 +3489,7 @@ class Axios {
3369
3489
 
3370
3490
  getUri(config) {
3371
3491
  config = mergeConfig(this.defaults, config);
3372
- const fullPath = buildFullPath(config.baseURL, config.url);
3492
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
3373
3493
  return buildURL(fullPath, config.params, config.paramsSerializer);
3374
3494
  }
3375
3495
  }