axios 1.4.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.4.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
  const FormData$1 = require('form-data');
@@ -568,8 +568,9 @@ const reduceDescriptors = (obj, reducer) => {
568
568
  const reducedDescriptors = {};
569
569
 
570
570
  forEach(descriptors, (descriptor, name) => {
571
- if (reducer(descriptor, name, obj) !== false) {
572
- reducedDescriptors[name] = descriptor;
571
+ let ret;
572
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
573
+ reducedDescriptors[name] = ret || descriptor;
573
574
  }
574
575
  });
575
576
 
@@ -1353,10 +1354,6 @@ function formDataToJSON(formData) {
1353
1354
  return null;
1354
1355
  }
1355
1356
 
1356
- const DEFAULT_CONTENT_TYPE = {
1357
- 'Content-Type': undefined
1358
- };
1359
-
1360
1357
  /**
1361
1358
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1362
1359
  * of the input
@@ -1495,19 +1492,16 @@ const defaults = {
1495
1492
 
1496
1493
  headers: {
1497
1494
  common: {
1498
- 'Accept': 'application/json, text/plain, */*'
1495
+ 'Accept': 'application/json, text/plain, */*',
1496
+ 'Content-Type': undefined
1499
1497
  }
1500
1498
  }
1501
1499
  };
1502
1500
 
1503
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1501
+ utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
1504
1502
  defaults.headers[method] = {};
1505
1503
  });
1506
1504
 
1507
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1508
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1509
- });
1510
-
1511
1505
  const defaults$1 = defaults;
1512
1506
 
1513
1507
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -1841,7 +1835,17 @@ class AxiosHeaders {
1841
1835
 
1842
1836
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1843
1837
 
1844
- utils.freezeMethods(AxiosHeaders.prototype);
1838
+ // reserved names hotfix
1839
+ utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
1840
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
1841
+ return {
1842
+ get: () => value,
1843
+ set(headerValue) {
1844
+ this[mapped] = headerValue;
1845
+ }
1846
+ }
1847
+ });
1848
+
1845
1849
  utils.freezeMethods(AxiosHeaders);
1846
1850
 
1847
1851
  const AxiosHeaders$1 = AxiosHeaders;
@@ -1961,7 +1965,7 @@ function buildFullPath(baseURL, requestedURL) {
1961
1965
  return requestedURL;
1962
1966
  }
1963
1967
 
1964
- const VERSION = "1.4.0";
1968
+ const VERSION = "1.5.1";
1965
1969
 
1966
1970
  function parseProtocol(url) {
1967
1971
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -2810,11 +2814,13 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2810
2814
  auth,
2811
2815
  protocol,
2812
2816
  family,
2813
- lookup,
2814
2817
  beforeRedirect: dispatchBeforeRedirect,
2815
2818
  beforeRedirects: {}
2816
2819
  };
2817
2820
 
2821
+ // cacheable-lookup integration hotfix
2822
+ !utils.isUndefined(lookup) && (options.lookup = lookup);
2823
+
2818
2824
  if (config.socketPath) {
2819
2825
  options.socketPath = config.socketPath;
2820
2826
  } else {
@@ -2888,7 +2894,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2888
2894
  delete res.headers['content-encoding'];
2889
2895
  }
2890
2896
 
2891
- switch (res.headers['content-encoding']) {
2897
+ switch ((res.headers['content-encoding'] || '').toLowerCase()) {
2892
2898
  /*eslint default-case:0*/
2893
2899
  case 'gzip':
2894
2900
  case 'x-gzip':
@@ -3021,7 +3027,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3021
3027
  // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
3022
3028
  const timeout = parseInt(config.timeout, 10);
3023
3029
 
3024
- if (isNaN(timeout)) {
3030
+ if (Number.isNaN(timeout)) {
3025
3031
  reject(new AxiosError(
3026
3032
  'error trying to parse `config.timeout` to int',
3027
3033
  AxiosError.ERR_BAD_OPTION_VALUE,
@@ -3240,11 +3246,16 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
3240
3246
  }
3241
3247
  }
3242
3248
 
3249
+ let contentType;
3250
+
3243
3251
  if (utils.isFormData(requestData)) {
3244
3252
  if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
3245
3253
  requestHeaders.setContentType(false); // Let the browser set it
3246
- } else {
3247
- requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
3254
+ } else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
3255
+ requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
3256
+ } else if(utils.isString(contentType = requestHeaders.getContentType())){
3257
+ // fix semicolon duplication issue for ReactNative FormData implementation
3258
+ requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'));
3248
3259
  }
3249
3260
  }
3250
3261
 
@@ -3437,7 +3448,7 @@ const knownAdapters = {
3437
3448
  };
3438
3449
 
3439
3450
  utils.forEach(knownAdapters, (fn, value) => {
3440
- if(fn) {
3451
+ if (fn) {
3441
3452
  try {
3442
3453
  Object.defineProperty(fn, 'name', {value});
3443
3454
  } catch (e) {
@@ -3447,6 +3458,10 @@ utils.forEach(knownAdapters, (fn, value) => {
3447
3458
  }
3448
3459
  });
3449
3460
 
3461
+ const renderReason = (reason) => `- ${reason}`;
3462
+
3463
+ const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
3464
+
3450
3465
  const adapters = {
3451
3466
  getAdapter: (adapters) => {
3452
3467
  adapters = utils.isArray(adapters) ? adapters : [adapters];
@@ -3455,30 +3470,44 @@ const adapters = {
3455
3470
  let nameOrAdapter;
3456
3471
  let adapter;
3457
3472
 
3473
+ const rejectedReasons = {};
3474
+
3458
3475
  for (let i = 0; i < length; i++) {
3459
3476
  nameOrAdapter = adapters[i];
3460
- if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
3477
+ let id;
3478
+
3479
+ adapter = nameOrAdapter;
3480
+
3481
+ if (!isResolvedHandle(nameOrAdapter)) {
3482
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3483
+
3484
+ if (adapter === undefined) {
3485
+ throw new AxiosError(`Unknown adapter '${id}'`);
3486
+ }
3487
+ }
3488
+
3489
+ if (adapter) {
3461
3490
  break;
3462
3491
  }
3492
+
3493
+ rejectedReasons[id || '#' + i] = adapter;
3463
3494
  }
3464
3495
 
3465
3496
  if (!adapter) {
3466
- if (adapter === false) {
3467
- throw new AxiosError(
3468
- `Adapter ${nameOrAdapter} is not supported by the environment`,
3469
- 'ERR_NOT_SUPPORT'
3497
+
3498
+ const reasons = Object.entries(rejectedReasons)
3499
+ .map(([id, state]) => `adapter ${id} ` +
3500
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
3470
3501
  );
3471
- }
3472
3502
 
3473
- throw new Error(
3474
- utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
3475
- `Adapter '${nameOrAdapter}' is not available in the build` :
3476
- `Unknown adapter '${nameOrAdapter}'`
3477
- );
3478
- }
3503
+ let s = length ?
3504
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3505
+ 'as no adapter specified';
3479
3506
 
3480
- if (!utils.isFunction(adapter)) {
3481
- throw new TypeError('adapter is not a function');
3507
+ throw new AxiosError(
3508
+ `There is no suitable adapter to dispatch the request ` + s,
3509
+ 'ERR_NOT_SUPPORT'
3510
+ );
3482
3511
  }
3483
3512
 
3484
3513
  return adapter;
@@ -3811,15 +3840,13 @@ class Axios {
3811
3840
  // Set config.method
3812
3841
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3813
3842
 
3814
- let contextHeaders;
3815
-
3816
3843
  // Flatten headers
3817
- contextHeaders = headers && utils.merge(
3844
+ let contextHeaders = headers && utils.merge(
3818
3845
  headers.common,
3819
3846
  headers[config.method]
3820
3847
  );
3821
3848
 
3822
- contextHeaders && utils.forEach(
3849
+ headers && utils.forEach(
3823
3850
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3824
3851
  (method) => {
3825
3852
  delete headers[method];
@@ -4229,6 +4256,8 @@ axios.AxiosHeaders = AxiosHeaders$1;
4229
4256
 
4230
4257
  axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
4231
4258
 
4259
+ axios.getAdapter = adapters.getAdapter;
4260
+
4232
4261
  axios.HttpStatusCode = HttpStatusCode$1;
4233
4262
 
4234
4263
  axios.default = axios;