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