axios 1.5.0 → 1.6.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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
- // Axios v1.5.0 Copyright (c) 2023 Matt Zabriskie and contributors
1
+ // Axios v1.6.0 Copyright (c) 2023 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -1383,7 +1383,7 @@ const defaults = {
1383
1383
 
1384
1384
  transitional: transitionalDefaults,
1385
1385
 
1386
- adapter: 'http' ,
1386
+ adapter: ['xhr', 'http'],
1387
1387
 
1388
1388
  transformRequest: [function transformRequest(data, headers) {
1389
1389
  const contentType = headers.getContentType() || '';
@@ -1965,7 +1965,7 @@ function buildFullPath(baseURL, requestedURL) {
1965
1965
  return requestedURL;
1966
1966
  }
1967
1967
 
1968
- const VERSION = "1.5.0";
1968
+ const VERSION = "1.6.0";
1969
1969
 
1970
1970
  function parseProtocol(url) {
1971
1971
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -2569,6 +2569,18 @@ const wrapAsync = (asyncExecutor) => {
2569
2569
  })
2570
2570
  };
2571
2571
 
2572
+ const resolveFamily = ({address, family}) => {
2573
+ if (!utils.isString(address)) {
2574
+ throw TypeError('address must be a string');
2575
+ }
2576
+ return ({
2577
+ address,
2578
+ family: family || (address.indexOf('.') < 0 ? 6 : 4)
2579
+ });
2580
+ };
2581
+
2582
+ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(address) ? address : {address, family});
2583
+
2572
2584
  /*eslint consistent-return:0*/
2573
2585
  const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2574
2586
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
@@ -2579,15 +2591,16 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2579
2591
  let rejected = false;
2580
2592
  let req;
2581
2593
 
2582
- if (lookup && utils.isAsyncFn(lookup)) {
2583
- lookup = callbackify$1(lookup, (entry) => {
2584
- if(utils.isString(entry)) {
2585
- entry = [entry, entry.indexOf('.') < 0 ? 6 : 4];
2586
- } else if (!utils.isArray(entry)) {
2587
- throw new TypeError('lookup async function must return an array [ip: string, family: number]]')
2588
- }
2589
- return entry;
2590
- });
2594
+ if (lookup) {
2595
+ const _lookup = callbackify$1(lookup, (value) => utils.isArray(value) ? value : [value]);
2596
+ // hotfix to support opt.all option which is required for node 20.x
2597
+ lookup = (hostname, opt, cb) => {
2598
+ _lookup(hostname, opt, (err, arg0, arg1) => {
2599
+ const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
2600
+
2601
+ opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
2602
+ });
2603
+ };
2591
2604
  }
2592
2605
 
2593
2606
  // temporary internal emitter until the AxiosRequest class will be implemented
@@ -2894,7 +2907,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2894
2907
  delete res.headers['content-encoding'];
2895
2908
  }
2896
2909
 
2897
- switch (res.headers['content-encoding']) {
2910
+ switch ((res.headers['content-encoding'] || '').toLowerCase()) {
2898
2911
  /*eslint default-case:0*/
2899
2912
  case 'gzip':
2900
2913
  case 'x-gzip':
@@ -2990,7 +3003,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2990
3003
  }
2991
3004
  response.data = responseData;
2992
3005
  } catch (err) {
2993
- reject(AxiosError.from(err, null, config, response.request, response));
3006
+ return reject(AxiosError.from(err, null, config, response.request, response));
2994
3007
  }
2995
3008
  settle(resolve, reject, response);
2996
3009
  });
@@ -3027,7 +3040,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3027
3040
  // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
3028
3041
  const timeout = parseInt(config.timeout, 10);
3029
3042
 
3030
- if (isNaN(timeout)) {
3043
+ if (Number.isNaN(timeout)) {
3031
3044
  reject(new AxiosError(
3032
3045
  'error trying to parse `config.timeout` to int',
3033
3046
  AxiosError.ERR_BAD_OPTION_VALUE,
@@ -3246,11 +3259,16 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
3246
3259
  }
3247
3260
  }
3248
3261
 
3262
+ let contentType;
3263
+
3249
3264
  if (utils.isFormData(requestData)) {
3250
3265
  if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
3251
3266
  requestHeaders.setContentType(false); // Let the browser set it
3252
- } else {
3253
- requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
3267
+ } else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
3268
+ requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
3269
+ } else if(utils.isString(contentType = requestHeaders.getContentType())){
3270
+ // fix semicolon duplication issue for ReactNative FormData implementation
3271
+ requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'));
3254
3272
  }
3255
3273
  }
3256
3274
 
@@ -3368,8 +3386,8 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
3368
3386
  // Specifically not if we're in a web worker, or react-native.
3369
3387
  if (platform.isStandardBrowserEnv) {
3370
3388
  // Add xsrf header
3371
- const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
3372
- && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
3389
+ // regarding CVE-2023-45857 config.withCredentials condition was removed temporarily
3390
+ const xsrfValue = isURLSameOrigin(fullPath) && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
3373
3391
 
3374
3392
  if (xsrfValue) {
3375
3393
  requestHeaders.set(config.xsrfHeaderName, xsrfValue);
@@ -3443,7 +3461,7 @@ const knownAdapters = {
3443
3461
  };
3444
3462
 
3445
3463
  utils.forEach(knownAdapters, (fn, value) => {
3446
- if(fn) {
3464
+ if (fn) {
3447
3465
  try {
3448
3466
  Object.defineProperty(fn, 'name', {value});
3449
3467
  } catch (e) {
@@ -3453,6 +3471,10 @@ utils.forEach(knownAdapters, (fn, value) => {
3453
3471
  }
3454
3472
  });
3455
3473
 
3474
+ const renderReason = (reason) => `- ${reason}`;
3475
+
3476
+ const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
3477
+
3456
3478
  const adapters = {
3457
3479
  getAdapter: (adapters) => {
3458
3480
  adapters = utils.isArray(adapters) ? adapters : [adapters];
@@ -3461,30 +3483,44 @@ const adapters = {
3461
3483
  let nameOrAdapter;
3462
3484
  let adapter;
3463
3485
 
3486
+ const rejectedReasons = {};
3487
+
3464
3488
  for (let i = 0; i < length; i++) {
3465
3489
  nameOrAdapter = adapters[i];
3466
- if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
3490
+ let id;
3491
+
3492
+ adapter = nameOrAdapter;
3493
+
3494
+ if (!isResolvedHandle(nameOrAdapter)) {
3495
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3496
+
3497
+ if (adapter === undefined) {
3498
+ throw new AxiosError(`Unknown adapter '${id}'`);
3499
+ }
3500
+ }
3501
+
3502
+ if (adapter) {
3467
3503
  break;
3468
3504
  }
3505
+
3506
+ rejectedReasons[id || '#' + i] = adapter;
3469
3507
  }
3470
3508
 
3471
3509
  if (!adapter) {
3472
- if (adapter === false) {
3473
- throw new AxiosError(
3474
- `Adapter ${nameOrAdapter} is not supported by the environment`,
3475
- 'ERR_NOT_SUPPORT'
3510
+
3511
+ const reasons = Object.entries(rejectedReasons)
3512
+ .map(([id, state]) => `adapter ${id} ` +
3513
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
3476
3514
  );
3477
- }
3478
3515
 
3479
- throw new Error(
3480
- utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
3481
- `Adapter '${nameOrAdapter}' is not available in the build` :
3482
- `Unknown adapter '${nameOrAdapter}'`
3483
- );
3484
- }
3516
+ let s = length ?
3517
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3518
+ 'as no adapter specified';
3485
3519
 
3486
- if (!utils.isFunction(adapter)) {
3487
- throw new TypeError('adapter is not a function');
3520
+ throw new AxiosError(
3521
+ `There is no suitable adapter to dispatch the request ` + s,
3522
+ 'ERR_NOT_SUPPORT'
3523
+ );
3488
3524
  }
3489
3525
 
3490
3526
  return adapter;