axios 1.18.0 → 1.19.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +192 -23
  3. package/dist/axios.js +410 -101
  4. package/dist/axios.min.js +3 -3
  5. package/dist/axios.min.js.map +1 -1
  6. package/dist/browser/axios.cjs +484 -119
  7. package/dist/esm/axios.js +484 -119
  8. package/dist/esm/axios.min.js +2 -2
  9. package/dist/esm/axios.min.js.map +1 -1
  10. package/dist/node/axios.cjs +589 -139
  11. package/index.d.cts +114 -74
  12. package/index.d.ts +112 -68
  13. package/lib/adapters/adapters.js +1 -1
  14. package/lib/adapters/fetch.js +27 -12
  15. package/lib/adapters/http.js +95 -34
  16. package/lib/adapters/xhr.js +1 -0
  17. package/lib/core/Axios.js +24 -6
  18. package/lib/core/AxiosError.js +46 -3
  19. package/lib/core/AxiosHeaders.js +124 -1
  20. package/lib/core/buildFullPath.js +45 -7
  21. package/lib/core/mergeConfig.js +19 -3
  22. package/lib/core/setFormDataHeaders.js +27 -0
  23. package/lib/env/data.js +1 -1
  24. package/lib/helpers/AxiosURLSearchParams.js +1 -3
  25. package/lib/helpers/HttpStatusCode.js +1 -0
  26. package/lib/helpers/buildURL.js +1 -0
  27. package/lib/helpers/combineURLs.js +11 -3
  28. package/lib/helpers/composeSignals.js +12 -1
  29. package/lib/helpers/cookies.js +5 -1
  30. package/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
  31. package/lib/helpers/formDataToJSON.js +11 -5
  32. package/lib/helpers/fromDataURI.js +4 -2
  33. package/lib/helpers/parseHeaders.js +5 -3
  34. package/lib/helpers/progressEventReducer.js +3 -3
  35. package/lib/helpers/resolveConfig.js +10 -19
  36. package/lib/helpers/shouldBypassProxy.js +120 -1
  37. package/lib/helpers/toFormData.js +8 -1
  38. package/lib/helpers/validator.js +1 -1
  39. package/lib/platform/node/classes/Buffer.js +11 -0
  40. package/lib/utils.js +17 -5
  41. package/package.json +22 -20
package/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Axios v1.18.0 Copyright (c) 2026 Matt Zabriskie and contributors */
1
+ /*! Axios v1.19.0 Copyright (c) 2026 Matt Zabriskie and contributors */
2
2
  /**
3
3
  * Create a bound version of a function with a specified `this` context
4
4
  *
@@ -292,6 +292,7 @@ const isBlob = kindOfTest('Blob');
292
292
  * @returns {boolean} True if value is a FileList, otherwise false
293
293
  */
294
294
  const isFileList = kindOfTest('FileList');
295
+ const isSet = kindOfTest('Set');
295
296
 
296
297
  /**
297
298
  * Determine if a value is a Stream
@@ -857,12 +858,23 @@ const toJSONObject = (obj) => {
857
858
  if (!('toJSON' in source)) {
858
859
  // add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230).
859
860
  visited.add(source);
860
- const target = isArray(source) ? [] : {};
861
861
 
862
- forEach(source, (value, key) => {
863
- const reducedValue = visit(value);
864
- !isUndefined(reducedValue) && (target[key] = reducedValue);
865
- });
862
+ let target;
863
+
864
+ if (isSet(source)) {
865
+ target = [];
866
+ for (const value of source) {
867
+ const reducedValue = visit(value);
868
+ !isUndefined(reducedValue) && target.push(reducedValue);
869
+ }
870
+ } else {
871
+ target = isArray(source) ? [] : {};
872
+
873
+ forEach(source, (value, key) => {
874
+ const reducedValue = visit(value);
875
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
876
+ });
877
+ }
866
878
 
867
879
  visited.delete(source);
868
880
 
@@ -1074,18 +1086,20 @@ var parseHeaders = (rawHeaders) => {
1074
1086
  key = line.substring(0, i).trim().toLowerCase();
1075
1087
  val = line.substring(i + 1).trim();
1076
1088
 
1077
- if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
1089
+ const hasKey = utils$1.hasOwnProp(parsed, key);
1090
+
1091
+ if (!key || (hasKey && utils$1.hasOwnProp(ignoreDuplicateOf, key))) {
1078
1092
  return;
1079
1093
  }
1080
1094
 
1081
1095
  if (key === 'set-cookie') {
1082
- if (parsed[key]) {
1096
+ if (hasKey) {
1083
1097
  parsed[key].push(val);
1084
1098
  } else {
1085
1099
  parsed[key] = [val];
1086
1100
  }
1087
1101
  } else {
1088
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1102
+ parsed[key] = hasKey ? parsed[key] + ', ' + val : val;
1089
1103
  }
1090
1104
  });
1091
1105
 
@@ -1175,6 +1189,124 @@ function parseTokens(str) {
1175
1189
  return tokens;
1176
1190
  }
1177
1191
 
1192
+ const parameterNameRE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
1193
+
1194
+ function trimOWS(value) {
1195
+ let start = 0;
1196
+ let end = value.length;
1197
+
1198
+ while (start < end) {
1199
+ const code = value.charCodeAt(start);
1200
+
1201
+ if (code !== 0x09 && code !== 0x20) {
1202
+ break;
1203
+ }
1204
+
1205
+ start += 1;
1206
+ }
1207
+
1208
+ while (end > start) {
1209
+ const code = value.charCodeAt(end - 1);
1210
+
1211
+ if (code !== 0x09 && code !== 0x20) {
1212
+ break;
1213
+ }
1214
+
1215
+ end -= 1;
1216
+ }
1217
+
1218
+ return start === 0 && end === value.length ? value : value.slice(start, end);
1219
+ }
1220
+
1221
+ function decodeQuotedString(value) {
1222
+ const last = value.length - 1;
1223
+
1224
+ if (last < 1 || value.charCodeAt(0) !== 0x22 || value.charCodeAt(last) !== 0x22) {
1225
+ return value;
1226
+ }
1227
+
1228
+ let decoded = '';
1229
+
1230
+ for (let i = 1; i < last; i++) {
1231
+ const code = value.charCodeAt(i);
1232
+
1233
+ if (code === 0x22) {
1234
+ return value;
1235
+ }
1236
+
1237
+ if (code === 0x5c) {
1238
+ i += 1;
1239
+
1240
+ if (i >= last) {
1241
+ return value;
1242
+ }
1243
+ }
1244
+
1245
+ decoded += value[i];
1246
+ }
1247
+
1248
+ return decoded;
1249
+ }
1250
+
1251
+ function parseParameters(value) {
1252
+ const parameters = Object.create(null);
1253
+ const str = String(value);
1254
+ let start = 0;
1255
+ let quoted = false;
1256
+ let escaped = false;
1257
+
1258
+ function parseParameter(end) {
1259
+ const part = trimOWS(str.slice(start, end));
1260
+ const equals = part.indexOf('=');
1261
+
1262
+ if (equals < 1) {
1263
+ return;
1264
+ }
1265
+
1266
+ const name = trimOWS(part.slice(0, equals));
1267
+
1268
+ if (!parameterNameRE.test(name)) {
1269
+ return;
1270
+ }
1271
+
1272
+ const normalizedName = name.toLowerCase();
1273
+
1274
+ if (
1275
+ normalizedName === '__proto__' ||
1276
+ normalizedName === 'constructor' ||
1277
+ normalizedName === 'prototype'
1278
+ ) {
1279
+ return;
1280
+ }
1281
+
1282
+ const parameterValue = trimOWS(part.slice(equals + 1));
1283
+ parameters[normalizedName] = decodeQuotedString(parameterValue);
1284
+ }
1285
+
1286
+ for (let i = 0; i < str.length; i++) {
1287
+ const code = str.charCodeAt(i);
1288
+
1289
+ if (quoted) {
1290
+ if (escaped) {
1291
+ escaped = false;
1292
+ } else if (code === 0x5c) {
1293
+ escaped = true;
1294
+ } else if (code === 0x22) {
1295
+ quoted = false;
1296
+ }
1297
+ } else if (code === 0x22) {
1298
+ quoted = true;
1299
+ } else if (code === 0x2c || code === 0x3b) {
1300
+ parseParameter(i);
1301
+ start = i + 1;
1302
+ }
1303
+ }
1304
+
1305
+ parseParameter(str.length);
1306
+
1307
+ return parameters;
1308
+ }
1309
+
1178
1310
  const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
1179
1311
 
1180
1312
  function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
@@ -1426,7 +1558,8 @@ let AxiosHeaders$1 = class AxiosHeaders {
1426
1558
  }
1427
1559
 
1428
1560
  getSetCookie() {
1429
- return this.get('set-cookie') || [];
1561
+ const value = this.get('set-cookie');
1562
+ return utils$1.isArray(value) ? value : value == null || value === false ? [] : [value];
1430
1563
  }
1431
1564
 
1432
1565
  get [Symbol.toStringTag]() {
@@ -1437,6 +1570,10 @@ let AxiosHeaders$1 = class AxiosHeaders {
1437
1570
  return thing instanceof this ? thing : new this(thing);
1438
1571
  }
1439
1572
 
1573
+ static parseParameters(value) {
1574
+ return parseParameters(value);
1575
+ }
1576
+
1440
1577
  static concat(first, ...targets) {
1441
1578
  const computed = new this(first);
1442
1579
 
@@ -1562,10 +1699,53 @@ function redactConfig(config, redactKeys) {
1562
1699
  return visit(config);
1563
1700
  }
1564
1701
 
1702
+ function stringifySafely$1(value) {
1703
+ try {
1704
+ return String(value);
1705
+ } catch (err) {
1706
+ return '';
1707
+ }
1708
+ }
1709
+
1710
+ function aggregateErrorMessage(error) {
1711
+ const message = error.errors
1712
+ .map((entry) => {
1713
+ try {
1714
+ return entry && entry.message ? stringifySafely$1(entry.message) : stringifySafely$1(entry);
1715
+ } catch (err) {
1716
+ return '';
1717
+ }
1718
+ })
1719
+ .filter(Boolean)
1720
+ .join('; ');
1721
+
1722
+ return message || error.name || 'AggregateError';
1723
+ }
1724
+
1565
1725
  let AxiosError$1 = class AxiosError extends Error {
1566
1726
  static from(error, code, config, request, response, customProps) {
1567
- const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
1568
- axiosError.cause = error;
1727
+ // `AggregateError` (thrown by Node on dual-stack/Happy-Eyeballs connection
1728
+ // failures) has an empty `message`; its detail lives in `errors[]`. Without
1729
+ // this, the wrapped error surfaces with a blank message (see #6721).
1730
+ let message = error.message;
1731
+ if (!message && utils$1.isArray(error.errors) && error.errors.length) {
1732
+ message = aggregateErrorMessage(error);
1733
+ }
1734
+
1735
+ const axiosError = new AxiosError(message, code || error.code, config, request, response);
1736
+ // Match native `Error` `cause` semantics: non-enumerable. The wrapped
1737
+ // error often carries circular internals (sockets, requests, agents), so
1738
+ // an enumerable `cause` makes structured loggers (pino/winston) and any
1739
+ // own-property walk throw "Converting circular structure to JSON".
1740
+ // Regression from #6982; see #7205. `__proto__: null` mirrors the
1741
+ // `message` descriptor below (prototype-pollution-safe descriptor).
1742
+ Object.defineProperty(axiosError, 'cause', {
1743
+ __proto__: null,
1744
+ value: error,
1745
+ writable: true,
1746
+ enumerable: false,
1747
+ configurable: true,
1748
+ });
1569
1749
  axiosError.name = error.name;
1570
1750
 
1571
1751
  // Preserve status from the original error if not already set from response
@@ -1804,7 +1984,10 @@ function toFormData$1(obj, formData, options) {
1804
1984
  }
1805
1985
 
1806
1986
  if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
1807
- return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
1987
+ if (useBlob && typeof _Blob === 'function') {
1988
+ return new _Blob([value]);
1989
+ }
1990
+ throw new AxiosError$1('Blob is not supported. Use a Buffer instead.', AxiosError$1.ERR_NOT_SUPPORT);
1808
1991
  }
1809
1992
 
1810
1993
  return value;
@@ -1981,9 +2164,7 @@ prototype.append = function append(name, value) {
1981
2164
 
1982
2165
  prototype.toString = function toString(encoder) {
1983
2166
  const _encode = encoder
1984
- ? function (value) {
1985
- return encoder.call(this, value, encode$1);
1986
- }
2167
+ ? (value) => encoder.call(this, value, encode$1)
1987
2168
  : encode$1;
1988
2169
 
1989
2170
  return this._pairs
@@ -2022,6 +2203,7 @@ function buildURL(url, params, options) {
2022
2203
  if (!params) {
2023
2204
  return url;
2024
2205
  }
2206
+ url = url || '';
2025
2207
 
2026
2208
  const _options = utils$1.isFunction(options)
2027
2209
  ? {
@@ -2241,12 +2423,18 @@ function throwIfDepthExceeded(index) {
2241
2423
  * @returns An array of strings.
2242
2424
  */
2243
2425
  function parsePropPath(name) {
2244
- // foo[x][y][z]
2245
- // foo.x.y.z
2246
- // foo-x-y-z
2247
- // foo x y z
2426
+ // foo[x][y][z] -> ['foo', 'x', 'y', 'z']
2427
+ // foo.x.y.z -> ['foo', 'x', 'y', 'z']
2428
+ // A path is split on `.` and on `[...]` groups. A segment — whether written
2429
+ // in dot notation or captured inside brackets — may contain any character
2430
+ // except `.`, `[` and `]`, so a key like `user-name` or `user name` is kept
2431
+ // literal instead of being split (#5402). `.`, `[` and `]` keep their existing
2432
+ // meaning, e.g. `foo[bar.baz]` -> ['foo', 'bar', 'baz'] and `[]` is an array push.
2433
+ // Excluding `[` from the bracket group also makes the match fail fast at the
2434
+ // next `[`, so a malformed name cannot rescan to the end of the string from
2435
+ // every unmatched `[` — parsing stays linear in the length of the name.
2248
2436
  const path = [];
2249
- const pattern = /\w+|\[(\w*)]/g;
2437
+ const pattern = /[^.[\]]+|\[([^.[\]]*)]/g;
2250
2438
  let match;
2251
2439
 
2252
2440
  while ((match = pattern.exec(name)) !== null) {
@@ -2678,7 +2866,7 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2678
2866
  }
2679
2867
  const rawLoaded = e.loaded;
2680
2868
  const total = e.lengthComputable ? e.total : undefined;
2681
- const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
2869
+ const loaded = Math.max(0, total != null ? Math.min(rawLoaded, total) : rawLoaded);
2682
2870
  const progressBytes = Math.max(0, loaded - bytesNotified);
2683
2871
  const rate = _speedometer(progressBytes);
2684
2872
 
@@ -2715,9 +2903,9 @@ const progressEventDecorator = (total, throttled) => {
2715
2903
  };
2716
2904
 
2717
2905
  const asyncDecorator =
2718
- (fn) =>
2906
+ (fn, scheduler = utils$1.asap) =>
2719
2907
  (...args) =>
2720
- utils$1.asap(() => fn(...args));
2908
+ scheduler(() => fn(...args));
2721
2909
 
2722
2910
  var isURLSameOrigin = platform.hasStandardBrowserEnv
2723
2911
  ? ((origin, isMSIE) => (url) => {
@@ -2773,7 +2961,11 @@ var cookies = platform.hasStandardBrowserEnv
2773
2961
  const cookie = cookies[i].replace(/^\s+/, '');
2774
2962
  const eq = cookie.indexOf('=');
2775
2963
  if (eq !== -1 && cookie.slice(0, eq) === name) {
2776
- return decodeURIComponent(cookie.slice(eq + 1));
2964
+ try {
2965
+ return decodeURIComponent(cookie.slice(eq + 1));
2966
+ } catch (e) {
2967
+ return cookie.slice(eq + 1);
2968
+ }
2777
2969
  }
2778
2970
  }
2779
2971
  return null;
@@ -2819,9 +3011,17 @@ function isAbsoluteURL(url) {
2819
3011
  * @returns {string} The combined URL
2820
3012
  */
2821
3013
  function combineURLs(baseURL, relativeURL) {
2822
- return relativeURL
2823
- ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2824
- : baseURL;
3014
+ if (!relativeURL) {
3015
+ return baseURL;
3016
+ }
3017
+
3018
+ let end = baseURL.length;
3019
+
3020
+ while (end > 0 && baseURL.charCodeAt(end - 1) === 47) {
3021
+ end--;
3022
+ }
3023
+
3024
+ return baseURL.slice(0, end) + '/' + relativeURL.replace(/^\/+/, '');
2825
3025
  }
2826
3026
 
2827
3027
  const malformedHttpProtocol = /^https?:(?!\/\/)/i;
@@ -2839,13 +3039,51 @@ function normalizeURLForProtocolCheck(url) {
2839
3039
  return stripLeadingC0ControlOrSpace(url).replace(httpProtocolControlCharacters, '');
2840
3040
  }
2841
3041
 
3042
+ // Redact the parts of a URL that can carry secrets before it is embedded in an
3043
+ // error message. AxiosError.toJSON() serializes `message` verbatim and errors
3044
+ // are commonly logged, while the opt-in `config.redact` model only cleans
3045
+ // config keys — it cannot reach the message. Redact only the genuinely
3046
+ // sensitive substrings — userinfo (credentials), query parameter values and
3047
+ // fragment contents — with the same REDACTED marker the config redaction uses,
3048
+ // while keeping the scheme, host, path and parameter names so the offending
3049
+ // request stays accurately identifiable.
3050
+ function redactFragment(fragment) {
3051
+ if (!fragment) {
3052
+ return fragment;
3053
+ }
3054
+
3055
+ return fragment.replace(/(^|&)([^=&]*=)?[^&]+/g, (match, separator, parameterName = '') => {
3056
+ return `${separator}${parameterName}${REDACTED}`;
3057
+ });
3058
+ }
3059
+
3060
+ function redactSensitiveURLParts(url) {
3061
+ const redactedURL = url.replace(/^(https?:\/{0,2})[^/?#]*@/i, `$1${REDACTED}@`);
3062
+ const fragmentIndex = redactedURL.indexOf('#');
3063
+ const urlWithoutFragment =
3064
+ fragmentIndex === -1 ? redactedURL : redactedURL.slice(0, fragmentIndex);
3065
+ const redactedURLWithoutFragment = urlWithoutFragment.replace(
3066
+ /([?&][^=&#]*=)[^&#]*/g,
3067
+ `$1${REDACTED}`
3068
+ );
3069
+
3070
+ if (fragmentIndex === -1) {
3071
+ return redactedURLWithoutFragment;
3072
+ }
3073
+
3074
+ return `${redactedURLWithoutFragment}#${redactFragment(redactedURL.slice(fragmentIndex + 1))}`;
3075
+ }
3076
+
2842
3077
  function assertValidHttpProtocolURL(url, config) {
2843
- if (typeof url === 'string' && malformedHttpProtocol.test(normalizeURLForProtocolCheck(url))) {
2844
- throw new AxiosError$1(
2845
- 'Invalid URL: missing "//" after protocol',
2846
- AxiosError$1.ERR_INVALID_URL,
2847
- config
2848
- );
3078
+ if (typeof url === 'string') {
3079
+ const normalizedURL = normalizeURLForProtocolCheck(url);
3080
+ if (malformedHttpProtocol.test(normalizedURL)) {
3081
+ throw new AxiosError$1(
3082
+ `Invalid URL ${JSON.stringify(redactSensitiveURLParts(normalizedURL))}: missing "//" after protocol`,
3083
+ AxiosError$1.ERR_INVALID_URL,
3084
+ config
3085
+ );
3086
+ }
2849
3087
  }
2850
3088
  }
2851
3089
 
@@ -2871,6 +3109,17 @@ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls, config) {
2871
3109
 
2872
3110
  const headersToObject = (thing) => (thing instanceof AxiosHeaders$1 ? { ...thing } : thing);
2873
3111
 
3112
+ const ownEnumerableKeys = (thing) => {
3113
+ if (Object.getOwnPropertySymbols && Object.getOwnPropertyDescriptor) {
3114
+ return Object.keys(thing).concat(
3115
+ Object.getOwnPropertySymbols(thing).filter(
3116
+ (symbol) => Object.getOwnPropertyDescriptor(thing, symbol).enumerable
3117
+ )
3118
+ );
3119
+ }
3120
+ return Object.keys(thing);
3121
+ };
3122
+
2874
3123
  /**
2875
3124
  * Config-specific merge-function which creates a new config-object
2876
3125
  * by merging two configuration objects together.
@@ -2882,6 +3131,7 @@ const headersToObject = (thing) => (thing instanceof AxiosHeaders$1 ? { ...thing
2882
3131
  */
2883
3132
  function mergeConfig$1(config1, config2) {
2884
3133
  // eslint-disable-next-line no-param-reassign
3134
+ config1 = config1 || {};
2885
3135
  config2 = config2 || {};
2886
3136
 
2887
3137
  // Use a null-prototype object so that downstream reads such as `config.auth`
@@ -2935,7 +3185,9 @@ function mergeConfig$1(config1, config2) {
2935
3185
  }
2936
3186
 
2937
3187
  function getMergedTransitionalOption(prop) {
2938
- const transitional2 = utils$1.hasOwnProp(config2, 'transitional') ? config2.transitional : undefined;
3188
+ const transitional2 = utils$1.hasOwnProp(config2, 'transitional')
3189
+ ? config2.transitional
3190
+ : undefined;
2939
3191
 
2940
3192
  if (!utils$1.isUndefined(transitional2)) {
2941
3193
  if (utils$1.isPlainObject(transitional2)) {
@@ -2947,7 +3199,9 @@ function mergeConfig$1(config1, config2) {
2947
3199
  }
2948
3200
  }
2949
3201
 
2950
- const transitional1 = utils$1.hasOwnProp(config1, 'transitional') ? config1.transitional : undefined;
3202
+ const transitional1 = utils$1.hasOwnProp(config1, 'transitional')
3203
+ ? config1.transitional
3204
+ : undefined;
2951
3205
 
2952
3206
  if (utils$1.isPlainObject(transitional1) && utils$1.hasOwnProp(transitional1, prop)) {
2953
3207
  return transitional1[prop];
@@ -2999,7 +3253,7 @@ function mergeConfig$1(config1, config2) {
2999
3253
  mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true),
3000
3254
  };
3001
3255
 
3002
- utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
3256
+ utils$1.forEach(ownEnumerableKeys({ ...config1, ...config2 }), function computeConfigValue(prop) {
3003
3257
  if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
3004
3258
  const merge = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
3005
3259
  const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : undefined;
@@ -3025,13 +3279,24 @@ function mergeConfig$1(config1, config2) {
3025
3279
 
3026
3280
  const FORM_DATA_CONTENT_HEADERS = ['content-type', 'content-length'];
3027
3281
 
3282
+ /**
3283
+ * Apply the headers generated by a FormData implementation to the request headers,
3284
+ * honoring the `formDataHeaderPolicy` option: with 'content-only', copy only the
3285
+ * content-* headers; otherwise merge all of them.
3286
+ *
3287
+ * @param {AxiosHeaders} headers - the request headers to mutate
3288
+ * @param {Object | null | undefined} formHeaders - headers produced by the FormData implementation
3289
+ * @param {String} [policy] - the resolved `formDataHeaderPolicy` config value
3290
+ *
3291
+ * @returns {void}
3292
+ */
3028
3293
  function setFormDataHeaders(headers, formHeaders, policy) {
3029
3294
  if (policy !== 'content-only') {
3030
3295
  headers.set(formHeaders);
3031
3296
  return;
3032
3297
  }
3033
3298
 
3034
- Object.entries(formHeaders).forEach(([key, val]) => {
3299
+ Object.entries(formHeaders || {}).forEach(([key, val]) => {
3035
3300
  if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
3036
3301
  headers.set(key, val);
3037
3302
  }
@@ -3081,10 +3346,14 @@ function resolveConfig(config) {
3081
3346
  const username = utils$1.getSafeProp(auth, 'username') || '';
3082
3347
  const password = utils$1.getSafeProp(auth, 'password') || '';
3083
3348
 
3084
- headers.set(
3085
- 'Authorization',
3086
- 'Basic ' + btoa(username + ':' + (password ? encodeUTF8$1(password) : ''))
3087
- );
3349
+ try {
3350
+ headers.set(
3351
+ 'Authorization',
3352
+ 'Basic ' + btoa(username + ':' + (password ? encodeUTF8$1(password) : ''))
3353
+ );
3354
+ } catch (e) {
3355
+ throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_OPTION_VALUE, config);
3356
+ }
3088
3357
  }
3089
3358
 
3090
3359
  if (utils$1.isFormData(data)) {
@@ -3335,6 +3604,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3335
3604
  config
3336
3605
  )
3337
3606
  );
3607
+ done();
3338
3608
  return;
3339
3609
  }
3340
3610
 
@@ -3386,7 +3656,18 @@ const composeSignals = (signals, timeout) => {
3386
3656
  signals = null;
3387
3657
  };
3388
3658
 
3389
- signals.forEach((signal) => signal.addEventListener('abort', onabort));
3659
+ signals.forEach((signal) => {
3660
+ if (aborted) {
3661
+ return;
3662
+ }
3663
+
3664
+ if (signal.aborted) {
3665
+ onabort.call(signal);
3666
+ return;
3667
+ }
3668
+
3669
+ signal.addEventListener('abort', onabort, { once: true });
3670
+ });
3390
3671
 
3391
3672
  const { signal } = controller;
3392
3673
 
@@ -3486,13 +3767,11 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
3486
3767
  };
3487
3768
 
3488
3769
  /**
3489
- * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
3490
- * - For base64: compute exact decoded size using length and padding;
3491
- * handle %XX at the character-count level (no string allocation).
3492
- * - For non-base64: compute the exact percent-decoded UTF-8 byte length.
3493
- *
3494
- * @param {string} url
3495
- * @returns {number}
3770
+ * Estimate data: URL byte lengths *without* allocating large buffers.
3771
+ * - Fetch percent-decodes a base64 body before decoding it.
3772
+ * - Node's Buffer.from(body, 'base64') sizes its backing allocation from the
3773
+ * raw body, including ignored characters and content after padding.
3774
+ * - Non-base64 data is percent-decoded and then encoded as UTF-8.
3496
3775
  */
3497
3776
  const isHexDigit = (charCode) =>
3498
3777
  (charCode >= 48 && charCode <= 57) ||
@@ -3502,7 +3781,89 @@ const isHexDigit = (charCode) =>
3502
3781
  const isPercentEncodedByte = (str, i, len) =>
3503
3782
  i + 2 < len && isHexDigit(str.charCodeAt(i + 1)) && isHexDigit(str.charCodeAt(i + 2));
3504
3783
 
3505
- function estimateDataURLDecodedBytes(url) {
3784
+ const hexValue = (charCode) => (charCode <= 57 ? charCode - 48 : (charCode & 0xdf) - 55);
3785
+
3786
+ const isBase64Char = (charCode) =>
3787
+ (charCode >= 65 && charCode <= 90) || // A-Z
3788
+ (charCode >= 97 && charCode <= 122) || // a-z
3789
+ (charCode >= 48 && charCode <= 57) || // 0-9
3790
+ charCode === 43 || // +
3791
+ charCode === 47 || // /
3792
+ charCode === 45 || // - (base64url)
3793
+ charCode === 95; // _ (base64url)
3794
+
3795
+ const isBase64Whitespace = (charCode) =>
3796
+ charCode === 9 || charCode === 10 || charCode === 12 || charCode === 13 || charCode === 32;
3797
+
3798
+ const base64Bytes = (significant) => {
3799
+ const groups = Math.floor(significant / 4);
3800
+ const remainder = significant % 4;
3801
+ return groups * 3 + (remainder === 2 ? 1 : remainder === 3 ? 2 : 0);
3802
+ };
3803
+
3804
+ // Buffer.byteLength(body, 'base64') uses the raw string length as an allocation
3805
+ // upper bound even when Buffer.from later ignores characters or stops at '='.
3806
+ const estimateBase64BufferAllocation = (body) => {
3807
+ const len = body.length;
3808
+ let padding = 0;
3809
+
3810
+ if (len > 0 && body.charCodeAt(len - 1) === 61 /* '=' */) {
3811
+ padding++;
3812
+
3813
+ if (len > 1 && body.charCodeAt(len - 2) === 61 /* '=' */) {
3814
+ padding++;
3815
+ }
3816
+ }
3817
+
3818
+ return Math.floor(((len - padding) * 3) / 4);
3819
+ };
3820
+
3821
+ const estimatePercentDecodedBase64Bytes = (body) => {
3822
+ const len = body.length;
3823
+ let significant = 0;
3824
+ let padding = 0;
3825
+ let invalid = false;
3826
+
3827
+ for (let i = 0; i < len; i++) {
3828
+ let code = body.charCodeAt(i);
3829
+
3830
+ if (code === 37 /* '%' */ && isPercentEncodedByte(body, i, len)) {
3831
+ code = hexValue(body.charCodeAt(i + 1)) * 16 + hexValue(body.charCodeAt(i + 2));
3832
+ i += 2;
3833
+ }
3834
+
3835
+ if (isBase64Whitespace(code)) {
3836
+ continue;
3837
+ }
3838
+
3839
+ if (code === 61 /* '=' */) {
3840
+ padding++;
3841
+ continue;
3842
+ }
3843
+
3844
+ if (!isBase64Char(code) || padding > 0) {
3845
+ invalid = true;
3846
+ continue;
3847
+ }
3848
+
3849
+ significant++;
3850
+ }
3851
+
3852
+ // Fetch rejects malformed forgiving-base64 input. Returning the raw-size
3853
+ // allocation bound keeps that invalid input from becoming a pre-check bypass.
3854
+ if (
3855
+ invalid ||
3856
+ padding > 2 ||
3857
+ (padding > 0 && (significant + padding) % 4 !== 0) ||
3858
+ significant % 4 === 1
3859
+ ) {
3860
+ return estimateBase64BufferAllocation(body);
3861
+ }
3862
+
3863
+ return base64Bytes(significant);
3864
+ };
3865
+
3866
+ const estimateDataURLBytes = (url, estimateBase64) => {
3506
3867
  if (!url || typeof url !== 'string') return 0;
3507
3868
  if (!url.startsWith('data:')) return 0;
3508
3869
 
@@ -3514,52 +3875,7 @@ function estimateDataURLDecodedBytes(url) {
3514
3875
  const isBase64 = /;base64/i.test(meta);
3515
3876
 
3516
3877
  if (isBase64) {
3517
- let effectiveLen = body.length;
3518
- const len = body.length; // cache length
3519
-
3520
- for (let i = 0; i < len; i++) {
3521
- if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
3522
- const a = body.charCodeAt(i + 1);
3523
- const b = body.charCodeAt(i + 2);
3524
- const isHex = isHexDigit(a) && isHexDigit(b);
3525
-
3526
- if (isHex) {
3527
- effectiveLen -= 2;
3528
- i += 2;
3529
- }
3530
- }
3531
- }
3532
-
3533
- let pad = 0;
3534
- let idx = len - 1;
3535
-
3536
- const tailIsPct3D = (j) =>
3537
- j >= 2 &&
3538
- body.charCodeAt(j - 2) === 37 && // '%'
3539
- body.charCodeAt(j - 1) === 51 && // '3'
3540
- (body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
3541
-
3542
- if (idx >= 0) {
3543
- if (body.charCodeAt(idx) === 61 /* '=' */) {
3544
- pad++;
3545
- idx--;
3546
- } else if (tailIsPct3D(idx)) {
3547
- pad++;
3548
- idx -= 3;
3549
- }
3550
- }
3551
-
3552
- if (pad === 1 && idx >= 0) {
3553
- if (body.charCodeAt(idx) === 61 /* '=' */) {
3554
- pad++;
3555
- } else if (tailIsPct3D(idx)) {
3556
- pad++;
3557
- }
3558
- }
3559
-
3560
- const groups = Math.floor(effectiveLen / 4);
3561
- const bytes = groups * 3 - (pad || 0);
3562
- return bytes > 0 ? bytes : 0;
3878
+ return estimateBase64(body);
3563
3879
  }
3564
3880
 
3565
3881
  // Compute UTF-8 byte length directly from UTF-16 code units without allocating
@@ -3589,9 +3905,25 @@ function estimateDataURLDecodedBytes(url) {
3589
3905
  }
3590
3906
  }
3591
3907
  return bytes;
3908
+ };
3909
+
3910
+ /**
3911
+ * Estimate the percent-decoded payload size used by Fetch data: URLs.
3912
+ *
3913
+ * @param {string} url
3914
+ * @returns {number}
3915
+ */
3916
+ function estimateDataURLDecodedBytes(url) {
3917
+ // Fetch removes URL fragments before processing a data: URL.
3918
+ const fragmentIndex = typeof url === 'string' ? url.indexOf('#') : -1;
3919
+
3920
+ return estimateDataURLBytes(
3921
+ fragmentIndex === -1 ? url : url.slice(0, fragmentIndex),
3922
+ estimatePercentDecodedBase64Bytes
3923
+ );
3592
3924
  }
3593
3925
 
3594
- const VERSION$1 = "1.18.0";
3926
+ const VERSION$1 = "1.19.0";
3595
3927
 
3596
3928
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
3597
3929
 
@@ -4135,7 +4467,17 @@ const factory = (env) => {
4135
4467
  const canceledError = composedSignal.reason;
4136
4468
  canceledError.config = config;
4137
4469
  request && (canceledError.request = request);
4138
- err !== canceledError && (canceledError.cause = err);
4470
+ if (err !== canceledError) {
4471
+ // Non-enumerable to match native Error `cause` semantics so loggers
4472
+ // don't recurse into circular fetch internals (see #7205).
4473
+ Object.defineProperty(canceledError, 'cause', {
4474
+ __proto__: null,
4475
+ value: err,
4476
+ writable: true,
4477
+ enumerable: false,
4478
+ configurable: true,
4479
+ });
4480
+ }
4139
4481
  throw canceledError;
4140
4482
  }
4141
4483
 
@@ -4157,18 +4499,23 @@ const factory = (env) => {
4157
4499
  }
4158
4500
 
4159
4501
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
4160
- throw Object.assign(
4161
- new AxiosError$1(
4162
- 'Network Error',
4163
- AxiosError$1.ERR_NETWORK,
4164
- config,
4165
- request,
4166
- err && err.response
4167
- ),
4168
- {
4169
- cause: err.cause || err,
4170
- }
4502
+ const networkError = new AxiosError$1(
4503
+ 'Network Error',
4504
+ AxiosError$1.ERR_NETWORK,
4505
+ config,
4506
+ request,
4507
+ err && err.response
4171
4508
  );
4509
+ // Non-enumerable to match native Error `cause` semantics so loggers
4510
+ // don't recurse into circular fetch internals (see #7205).
4511
+ Object.defineProperty(networkError, 'cause', {
4512
+ __proto__: null,
4513
+ value: err.cause || err,
4514
+ writable: true,
4515
+ enumerable: false,
4516
+ configurable: true,
4517
+ });
4518
+ throw networkError;
4172
4519
  }
4173
4520
 
4174
4521
  throw AxiosError$1.from(err, err && err.code, config, request, err && err.response);
@@ -4306,7 +4653,7 @@ function getAdapter$1(adapters, config) {
4306
4653
 
4307
4654
  throw new AxiosError$1(
4308
4655
  `There is no suitable adapter to dispatch the request ` + s,
4309
- 'ERR_NOT_SUPPORT'
4656
+ AxiosError$1.ERR_NOT_SUPPORT
4310
4657
  );
4311
4658
  }
4312
4659
 
@@ -4487,7 +4834,7 @@ validators$1.spelling = function spelling(correctSpelling) {
4487
4834
  */
4488
4835
 
4489
4836
  function assertOptions(options, schema, allowUnknown) {
4490
- if (typeof options !== 'object') {
4837
+ if (typeof options !== 'object' || options === null) {
4491
4838
  throw new AxiosError$1('options must be an object', AxiosError$1.ERR_BAD_OPTION_VALUE);
4492
4839
  }
4493
4840
  const keys = Object.keys(options);
@@ -4716,17 +5063,35 @@ let Axios$1 = class Axios {
4716
5063
  const onFulfilled = requestInterceptorChain[i++];
4717
5064
  const onRejected = requestInterceptorChain[i++];
4718
5065
  try {
4719
- newConfig = onFulfilled(newConfig);
5066
+ newConfig = onFulfilled ? onFulfilled(newConfig) : newConfig;
4720
5067
  } catch (error) {
4721
- onRejected.call(this, error);
5068
+ if (!onRejected) {
5069
+ promise = Promise.reject(error);
5070
+ break;
5071
+ }
5072
+
5073
+ try {
5074
+ const rejectedResult = onRejected.call(this, error);
5075
+
5076
+ if (utils$1.isThenable(rejectedResult)) {
5077
+ promise = Promise.resolve(rejectedResult).then(() =>
5078
+ dispatchRequest.call(this, newConfig)
5079
+ );
5080
+ }
5081
+ } catch (rejectedError) {
5082
+ promise = Promise.reject(rejectedError);
5083
+ }
5084
+
4722
5085
  break;
4723
5086
  }
4724
5087
  }
4725
5088
 
4726
- try {
4727
- promise = dispatchRequest.call(this, newConfig);
4728
- } catch (error) {
4729
- return Promise.reject(error);
5089
+ if (!promise) {
5090
+ try {
5091
+ promise = dispatchRequest.call(this, newConfig);
5092
+ } catch (error) {
5093
+ promise = Promise.reject(error);
5094
+ }
4730
5095
  }
4731
5096
 
4732
5097
  i = 0;
@@ -5019,6 +5384,7 @@ const HttpStatusCode$1 = {
5019
5384
  LoopDetected: 508,
5020
5385
  NotExtended: 510,
5021
5386
  NetworkAuthenticationRequired: 511,
5387
+ WebServerReturnsAnUnknownError: 520,
5022
5388
  WebServerIsDown: 521,
5023
5389
  ConnectionTimedOut: 522,
5024
5390
  OriginIsUnreachable: 523,
@@ -5122,4 +5488,3 @@ const {
5122
5488
  } = axios;
5123
5489
 
5124
5490
  export { Axios, AxiosError, AxiosHeaders, Cancel, CancelToken, CanceledError, HttpStatusCode, VERSION, all, create, axios as default, formToJSON, getAdapter, isAxiosError, isCancel, mergeConfig, spread, toFormData };
5125
- //# sourceMappingURL=axios.js.map