axios 1.4.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.4.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
  function bind(fn, thisArg) {
@@ -545,8 +545,9 @@ const reduceDescriptors = (obj, reducer) => {
545
545
  const reducedDescriptors = {};
546
546
 
547
547
  forEach(descriptors, (descriptor, name) => {
548
- if (reducer(descriptor, name, obj) !== false) {
549
- reducedDescriptors[name] = descriptor;
548
+ let ret;
549
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
550
+ reducedDescriptors[name] = ret || descriptor;
550
551
  }
551
552
  });
552
553
 
@@ -1388,10 +1389,6 @@ function formDataToJSON(formData) {
1388
1389
  return null;
1389
1390
  }
1390
1391
 
1391
- const DEFAULT_CONTENT_TYPE = {
1392
- 'Content-Type': undefined
1393
- };
1394
-
1395
1392
  /**
1396
1393
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1397
1394
  * of the input
@@ -1530,19 +1527,16 @@ const defaults = {
1530
1527
 
1531
1528
  headers: {
1532
1529
  common: {
1533
- 'Accept': 'application/json, text/plain, */*'
1530
+ 'Accept': 'application/json, text/plain, */*',
1531
+ 'Content-Type': undefined
1534
1532
  }
1535
1533
  }
1536
1534
  };
1537
1535
 
1538
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1536
+ utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
1539
1537
  defaults.headers[method] = {};
1540
1538
  });
1541
1539
 
1542
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1543
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1544
- });
1545
-
1546
1540
  var defaults$1 = defaults;
1547
1541
 
1548
1542
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -1876,7 +1870,17 @@ class AxiosHeaders {
1876
1870
 
1877
1871
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1878
1872
 
1879
- utils.freezeMethods(AxiosHeaders.prototype);
1873
+ // reserved names hotfix
1874
+ utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
1875
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
1876
+ return {
1877
+ get: () => value,
1878
+ set(headerValue) {
1879
+ this[mapped] = headerValue;
1880
+ }
1881
+ }
1882
+ });
1883
+
1880
1884
  utils.freezeMethods(AxiosHeaders);
1881
1885
 
1882
1886
  var AxiosHeaders$1 = AxiosHeaders;
@@ -2211,11 +2215,16 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2211
2215
  }
2212
2216
  }
2213
2217
 
2218
+ let contentType;
2219
+
2214
2220
  if (utils.isFormData(requestData)) {
2215
2221
  if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
2216
2222
  requestHeaders.setContentType(false); // Let the browser set it
2217
- } else {
2218
- 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'));
2219
2228
  }
2220
2229
  }
2221
2230
 
@@ -2333,8 +2342,8 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2333
2342
  // Specifically not if we're in a web worker, or react-native.
2334
2343
  if (platform.isStandardBrowserEnv) {
2335
2344
  // Add xsrf header
2336
- const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
2337
- && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2345
+ // regarding CVE-2023-45857 config.withCredentials condition was removed temporarily
2346
+ const xsrfValue = isURLSameOrigin(fullPath) && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2338
2347
 
2339
2348
  if (xsrfValue) {
2340
2349
  requestHeaders.set(config.xsrfHeaderName, xsrfValue);
@@ -2408,7 +2417,7 @@ const knownAdapters = {
2408
2417
  };
2409
2418
 
2410
2419
  utils.forEach(knownAdapters, (fn, value) => {
2411
- if(fn) {
2420
+ if (fn) {
2412
2421
  try {
2413
2422
  Object.defineProperty(fn, 'name', {value});
2414
2423
  } catch (e) {
@@ -2418,6 +2427,10 @@ utils.forEach(knownAdapters, (fn, value) => {
2418
2427
  }
2419
2428
  });
2420
2429
 
2430
+ const renderReason = (reason) => `- ${reason}`;
2431
+
2432
+ const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
2433
+
2421
2434
  var adapters = {
2422
2435
  getAdapter: (adapters) => {
2423
2436
  adapters = utils.isArray(adapters) ? adapters : [adapters];
@@ -2426,30 +2439,44 @@ var adapters = {
2426
2439
  let nameOrAdapter;
2427
2440
  let adapter;
2428
2441
 
2442
+ const rejectedReasons = {};
2443
+
2429
2444
  for (let i = 0; i < length; i++) {
2430
2445
  nameOrAdapter = adapters[i];
2431
- 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) {
2432
2459
  break;
2433
2460
  }
2461
+
2462
+ rejectedReasons[id || '#' + i] = adapter;
2434
2463
  }
2435
2464
 
2436
2465
  if (!adapter) {
2437
- if (adapter === false) {
2438
- throw new AxiosError(
2439
- `Adapter ${nameOrAdapter} is not supported by the environment`,
2440
- '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')
2441
2470
  );
2442
- }
2443
2471
 
2444
- throw new Error(
2445
- utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
2446
- `Adapter '${nameOrAdapter}' is not available in the build` :
2447
- `Unknown adapter '${nameOrAdapter}'`
2448
- );
2449
- }
2472
+ let s = length ?
2473
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
2474
+ 'as no adapter specified';
2450
2475
 
2451
- if (!utils.isFunction(adapter)) {
2452
- 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
+ );
2453
2480
  }
2454
2481
 
2455
2482
  return adapter;
@@ -2631,7 +2658,7 @@ function mergeConfig(config1, config2) {
2631
2658
  return config;
2632
2659
  }
2633
2660
 
2634
- const VERSION = "1.4.0";
2661
+ const VERSION = "1.6.0";
2635
2662
 
2636
2663
  const validators$1 = {};
2637
2664
 
@@ -2784,15 +2811,13 @@ class Axios {
2784
2811
  // Set config.method
2785
2812
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2786
2813
 
2787
- let contextHeaders;
2788
-
2789
2814
  // Flatten headers
2790
- contextHeaders = headers && utils.merge(
2815
+ let contextHeaders = headers && utils.merge(
2791
2816
  headers.common,
2792
2817
  headers[config.method]
2793
2818
  );
2794
2819
 
2795
- contextHeaders && utils.forEach(
2820
+ headers && utils.forEach(
2796
2821
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
2797
2822
  (method) => {
2798
2823
  delete headers[method];
@@ -3202,6 +3227,8 @@ axios.AxiosHeaders = AxiosHeaders$1;
3202
3227
 
3203
3228
  axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3204
3229
 
3230
+ axios.getAdapter = adapters.getAdapter;
3231
+
3205
3232
  axios.HttpStatusCode = HttpStatusCode$1;
3206
3233
 
3207
3234
  axios.default = axios;