axios 1.5.0 → 1.5.1

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.5.1 Copyright (c) 2023 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  function bind(fn, thisArg) {
@@ -1418,7 +1418,7 @@ const defaults = {
1418
1418
 
1419
1419
  transitional: transitionalDefaults,
1420
1420
 
1421
- adapter: platform.isNode ? 'http' : 'xhr',
1421
+ adapter: ['xhr', 'http'],
1422
1422
 
1423
1423
  transformRequest: [function transformRequest(data, headers) {
1424
1424
  const contentType = headers.getContentType() || '';
@@ -2215,11 +2215,16 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2215
2215
  }
2216
2216
  }
2217
2217
 
2218
+ let contentType;
2219
+
2218
2220
  if (utils.isFormData(requestData)) {
2219
2221
  if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
2220
2222
  requestHeaders.setContentType(false); // Let the browser set it
2221
- } else {
2222
- requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
2223
+ } else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
2224
+ requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
2225
+ } else if(utils.isString(contentType = requestHeaders.getContentType())){
2226
+ // fix semicolon duplication issue for ReactNative FormData implementation
2227
+ requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'));
2223
2228
  }
2224
2229
  }
2225
2230
 
@@ -2412,7 +2417,7 @@ const knownAdapters = {
2412
2417
  };
2413
2418
 
2414
2419
  utils.forEach(knownAdapters, (fn, value) => {
2415
- if(fn) {
2420
+ if (fn) {
2416
2421
  try {
2417
2422
  Object.defineProperty(fn, 'name', {value});
2418
2423
  } catch (e) {
@@ -2422,6 +2427,10 @@ utils.forEach(knownAdapters, (fn, value) => {
2422
2427
  }
2423
2428
  });
2424
2429
 
2430
+ const renderReason = (reason) => `- ${reason}`;
2431
+
2432
+ const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
2433
+
2425
2434
  var adapters = {
2426
2435
  getAdapter: (adapters) => {
2427
2436
  adapters = utils.isArray(adapters) ? adapters : [adapters];
@@ -2430,30 +2439,44 @@ var adapters = {
2430
2439
  let nameOrAdapter;
2431
2440
  let adapter;
2432
2441
 
2442
+ const rejectedReasons = {};
2443
+
2433
2444
  for (let i = 0; i < length; i++) {
2434
2445
  nameOrAdapter = adapters[i];
2435
- if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
2446
+ let id;
2447
+
2448
+ adapter = nameOrAdapter;
2449
+
2450
+ if (!isResolvedHandle(nameOrAdapter)) {
2451
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
2452
+
2453
+ if (adapter === undefined) {
2454
+ throw new AxiosError(`Unknown adapter '${id}'`);
2455
+ }
2456
+ }
2457
+
2458
+ if (adapter) {
2436
2459
  break;
2437
2460
  }
2461
+
2462
+ rejectedReasons[id || '#' + i] = adapter;
2438
2463
  }
2439
2464
 
2440
2465
  if (!adapter) {
2441
- if (adapter === false) {
2442
- throw new AxiosError(
2443
- `Adapter ${nameOrAdapter} is not supported by the environment`,
2444
- 'ERR_NOT_SUPPORT'
2466
+
2467
+ const reasons = Object.entries(rejectedReasons)
2468
+ .map(([id, state]) => `adapter ${id} ` +
2469
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
2445
2470
  );
2446
- }
2447
2471
 
2448
- throw new Error(
2449
- utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
2450
- `Adapter '${nameOrAdapter}' is not available in the build` :
2451
- `Unknown adapter '${nameOrAdapter}'`
2452
- );
2453
- }
2472
+ let s = length ?
2473
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
2474
+ 'as no adapter specified';
2454
2475
 
2455
- if (!utils.isFunction(adapter)) {
2456
- throw new TypeError('adapter is not a function');
2476
+ throw new AxiosError(
2477
+ `There is no suitable adapter to dispatch the request ` + s,
2478
+ 'ERR_NOT_SUPPORT'
2479
+ );
2457
2480
  }
2458
2481
 
2459
2482
  return adapter;
@@ -2635,7 +2658,7 @@ function mergeConfig(config1, config2) {
2635
2658
  return config;
2636
2659
  }
2637
2660
 
2638
- const VERSION = "1.5.0";
2661
+ const VERSION = "1.5.1";
2639
2662
 
2640
2663
  const validators$1 = {};
2641
2664