axios 1.2.0-alpha.1 → 1.2.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.2.0-alpha.1 Copyright (c) 2022 Matt Zabriskie and contributors
1
+ // Axios v1.2.0 Copyright (c) 2022 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -618,6 +618,37 @@ const toFiniteNumber = (value, defaultValue) => {
618
618
  return Number.isFinite(value) ? value : defaultValue;
619
619
  };
620
620
 
621
+ const toJSONObject = (obj) => {
622
+ const stack = new Array(10);
623
+
624
+ const visit = (source, i) => {
625
+
626
+ if (isObject(source)) {
627
+ if (stack.indexOf(source) >= 0) {
628
+ return;
629
+ }
630
+
631
+ if(!('toJSON' in source)) {
632
+ stack[i] = source;
633
+ const target = isArray(source) ? [] : {};
634
+
635
+ forEach(source, (value, key) => {
636
+ const reducedValue = visit(value, i + 1);
637
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
638
+ });
639
+
640
+ stack[i] = undefined;
641
+
642
+ return target;
643
+ }
644
+ }
645
+
646
+ return source;
647
+ };
648
+
649
+ return visit(obj, 0);
650
+ };
651
+
621
652
  const utils = {
622
653
  isArray,
623
654
  isArrayBuffer,
@@ -663,7 +694,8 @@ const utils = {
663
694
  toFiniteNumber,
664
695
  findKey,
665
696
  global: _global,
666
- isContextDefined
697
+ isContextDefined,
698
+ toJSONObject
667
699
  };
668
700
 
669
701
  /**
@@ -709,7 +741,7 @@ utils.inherits(AxiosError, Error, {
709
741
  columnNumber: this.columnNumber,
710
742
  stack: this.stack,
711
743
  // Axios
712
- config: this.config,
744
+ config: utils.toJSONObject(this.config),
713
745
  code: this.code,
714
746
  status: this.response && this.response.status ? this.response.status : null
715
747
  };
@@ -1281,148 +1313,162 @@ function formDataToJSON(formData) {
1281
1313
  return null;
1282
1314
  }
1283
1315
 
1316
+ const DEFAULT_CONTENT_TYPE = {
1317
+ 'Content-Type': undefined
1318
+ };
1319
+
1284
1320
  /**
1285
- * Resolve or reject a Promise based on response status.
1321
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1322
+ * of the input
1286
1323
  *
1287
- * @param {Function} resolve A function that resolves the promise.
1288
- * @param {Function} reject A function that rejects the promise.
1289
- * @param {object} response The response.
1324
+ * @param {any} rawValue - The value to be stringified.
1325
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
1326
+ * @param {Function} encoder - A function that takes a value and returns a string.
1290
1327
  *
1291
- * @returns {object} The response.
1328
+ * @returns {string} A stringified version of the rawValue.
1292
1329
  */
1293
- function settle(resolve, reject, response) {
1294
- const validateStatus = response.config.validateStatus;
1295
- if (!response.status || !validateStatus || validateStatus(response.status)) {
1296
- resolve(response);
1297
- } else {
1298
- reject(new AxiosError(
1299
- 'Request failed with status code ' + response.status,
1300
- [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1301
- response.config,
1302
- response.request,
1303
- response
1304
- ));
1330
+ function stringifySafely(rawValue, parser, encoder) {
1331
+ if (utils.isString(rawValue)) {
1332
+ try {
1333
+ (parser || JSON.parse)(rawValue);
1334
+ return utils.trim(rawValue);
1335
+ } catch (e) {
1336
+ if (e.name !== 'SyntaxError') {
1337
+ throw e;
1338
+ }
1339
+ }
1305
1340
  }
1306
- }
1307
1341
 
1308
- /**
1309
- * Determines whether the specified URL is absolute
1310
- *
1311
- * @param {string} url The URL to test
1312
- *
1313
- * @returns {boolean} True if the specified URL is absolute, otherwise false
1314
- */
1315
- function isAbsoluteURL(url) {
1316
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1317
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1318
- // by any combination of letters, digits, plus, period, or hyphen.
1319
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1342
+ return (encoder || JSON.stringify)(rawValue);
1320
1343
  }
1321
1344
 
1322
- /**
1323
- * Creates a new URL by combining the specified URLs
1324
- *
1325
- * @param {string} baseURL The base URL
1326
- * @param {string} relativeURL The relative URL
1327
- *
1328
- * @returns {string} The combined URL
1329
- */
1330
- function combineURLs(baseURL, relativeURL) {
1331
- return relativeURL
1332
- ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1333
- : baseURL;
1334
- }
1345
+ const defaults = {
1335
1346
 
1336
- /**
1337
- * Creates a new URL by combining the baseURL with the requestedURL,
1338
- * only when the requestedURL is not already an absolute URL.
1339
- * If the requestURL is absolute, this function returns the requestedURL untouched.
1340
- *
1341
- * @param {string} baseURL The base URL
1342
- * @param {string} requestedURL Absolute or relative URL to combine
1343
- *
1344
- * @returns {string} The combined full path
1345
- */
1346
- function buildFullPath(baseURL, requestedURL) {
1347
- if (baseURL && !isAbsoluteURL(requestedURL)) {
1348
- return combineURLs(baseURL, requestedURL);
1349
- }
1350
- return requestedURL;
1351
- }
1347
+ transitional: transitionalDefaults,
1352
1348
 
1353
- const VERSION = "1.2.0-alpha.1";
1349
+ adapter: ['xhr', 'http'],
1354
1350
 
1355
- /**
1356
- * A `CanceledError` is an object that is thrown when an operation is canceled.
1357
- *
1358
- * @param {string=} message The message.
1359
- * @param {Object=} config The config.
1360
- * @param {Object=} request The request.
1361
- *
1362
- * @returns {CanceledError} The created error.
1363
- */
1364
- function CanceledError(message, config, request) {
1365
- // eslint-disable-next-line no-eq-null,eqeqeq
1366
- AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1367
- this.name = 'CanceledError';
1368
- }
1351
+ transformRequest: [function transformRequest(data, headers) {
1352
+ const contentType = headers.getContentType() || '';
1353
+ const hasJSONContentType = contentType.indexOf('application/json') > -1;
1354
+ const isObjectPayload = utils.isObject(data);
1369
1355
 
1370
- utils.inherits(CanceledError, AxiosError, {
1371
- __CANCEL__: true
1372
- });
1356
+ if (isObjectPayload && utils.isHTMLForm(data)) {
1357
+ data = new FormData(data);
1358
+ }
1373
1359
 
1374
- function parseProtocol(url) {
1375
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1376
- return match && match[1] || '';
1377
- }
1360
+ const isFormData = utils.isFormData(data);
1378
1361
 
1379
- const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
1362
+ if (isFormData) {
1363
+ if (!hasJSONContentType) {
1364
+ return data;
1365
+ }
1366
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1367
+ }
1380
1368
 
1381
- /**
1382
- * Parse data uri to a Buffer or Blob
1383
- *
1384
- * @param {String} uri
1385
- * @param {?Boolean} asBlob
1386
- * @param {?Object} options
1387
- * @param {?Function} options.Blob
1388
- *
1389
- * @returns {Buffer|Blob}
1390
- */
1391
- function fromDataURI(uri, asBlob, options) {
1392
- const _Blob = options && options.Blob || platform.classes.Blob;
1393
- const protocol = parseProtocol(uri);
1369
+ if (utils.isArrayBuffer(data) ||
1370
+ utils.isBuffer(data) ||
1371
+ utils.isStream(data) ||
1372
+ utils.isFile(data) ||
1373
+ utils.isBlob(data)
1374
+ ) {
1375
+ return data;
1376
+ }
1377
+ if (utils.isArrayBufferView(data)) {
1378
+ return data.buffer;
1379
+ }
1380
+ if (utils.isURLSearchParams(data)) {
1381
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1382
+ return data.toString();
1383
+ }
1394
1384
 
1395
- if (asBlob === undefined && _Blob) {
1396
- asBlob = true;
1397
- }
1385
+ let isFileList;
1398
1386
 
1399
- if (protocol === 'data') {
1400
- uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
1387
+ if (isObjectPayload) {
1388
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1389
+ return toURLEncodedForm(data, this.formSerializer).toString();
1390
+ }
1401
1391
 
1402
- const match = DATA_URL_PATTERN.exec(uri);
1392
+ if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1393
+ const _FormData = this.env && this.env.FormData;
1403
1394
 
1404
- if (!match) {
1405
- throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
1395
+ return toFormData(
1396
+ isFileList ? {'files[]': data} : data,
1397
+ _FormData && new _FormData(),
1398
+ this.formSerializer
1399
+ );
1400
+ }
1406
1401
  }
1407
1402
 
1408
- const mime = match[1];
1409
- const isBase64 = match[2];
1410
- const body = match[3];
1411
- const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
1403
+ if (isObjectPayload || hasJSONContentType ) {
1404
+ headers.setContentType('application/json', false);
1405
+ return stringifySafely(data);
1406
+ }
1412
1407
 
1413
- if (asBlob) {
1414
- if (!_Blob) {
1415
- throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
1416
- }
1408
+ return data;
1409
+ }],
1417
1410
 
1418
- return new _Blob([buffer], {type: mime});
1411
+ transformResponse: [function transformResponse(data) {
1412
+ const transitional = this.transitional || defaults.transitional;
1413
+ const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1414
+ const JSONRequested = this.responseType === 'json';
1415
+
1416
+ if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1417
+ const silentJSONParsing = transitional && transitional.silentJSONParsing;
1418
+ const strictJSONParsing = !silentJSONParsing && JSONRequested;
1419
+
1420
+ try {
1421
+ return JSON.parse(data);
1422
+ } catch (e) {
1423
+ if (strictJSONParsing) {
1424
+ if (e.name === 'SyntaxError') {
1425
+ throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
1426
+ }
1427
+ throw e;
1428
+ }
1429
+ }
1419
1430
  }
1420
1431
 
1421
- return buffer;
1432
+ return data;
1433
+ }],
1434
+
1435
+ /**
1436
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
1437
+ * timeout is not created.
1438
+ */
1439
+ timeout: 0,
1440
+
1441
+ xsrfCookieName: 'XSRF-TOKEN',
1442
+ xsrfHeaderName: 'X-XSRF-TOKEN',
1443
+
1444
+ maxContentLength: -1,
1445
+ maxBodyLength: -1,
1446
+
1447
+ env: {
1448
+ FormData: platform.classes.FormData,
1449
+ Blob: platform.classes.Blob
1450
+ },
1451
+
1452
+ validateStatus: function validateStatus(status) {
1453
+ return status >= 200 && status < 300;
1454
+ },
1455
+
1456
+ headers: {
1457
+ common: {
1458
+ 'Accept': 'application/json, text/plain, */*'
1459
+ }
1422
1460
  }
1461
+ };
1423
1462
 
1424
- throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
1425
- }
1463
+ utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1464
+ defaults.headers[method] = {};
1465
+ });
1466
+
1467
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1468
+ defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1469
+ });
1470
+
1471
+ const defaults$1 = defaults;
1426
1472
 
1427
1473
  // RawAxiosHeaders whose duplicates are ignored by node
1428
1474
  // c.f. https://nodejs.org/api/http.html#http_message_headers
@@ -1727,24 +1773,194 @@ class AxiosHeaders {
1727
1773
  function defineAccessor(_header) {
1728
1774
  const lHeader = normalizeHeader(_header);
1729
1775
 
1730
- if (!accessors[lHeader]) {
1731
- buildAccessors(prototype, _header);
1732
- accessors[lHeader] = true;
1733
- }
1776
+ if (!accessors[lHeader]) {
1777
+ buildAccessors(prototype, _header);
1778
+ accessors[lHeader] = true;
1779
+ }
1780
+ }
1781
+
1782
+ utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1783
+
1784
+ return this;
1785
+ }
1786
+ }
1787
+
1788
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1789
+
1790
+ utils.freezeMethods(AxiosHeaders.prototype);
1791
+ utils.freezeMethods(AxiosHeaders);
1792
+
1793
+ const AxiosHeaders$1 = AxiosHeaders;
1794
+
1795
+ /**
1796
+ * Transform the data for a request or a response
1797
+ *
1798
+ * @param {Array|Function} fns A single function or Array of functions
1799
+ * @param {?Object} response The response object
1800
+ *
1801
+ * @returns {*} The resulting transformed data
1802
+ */
1803
+ function transformData(fns, response) {
1804
+ const config = this || defaults$1;
1805
+ const context = response || config;
1806
+ const headers = AxiosHeaders$1.from(context.headers);
1807
+ let data = context.data;
1808
+
1809
+ utils.forEach(fns, function transform(fn) {
1810
+ data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
1811
+ });
1812
+
1813
+ headers.normalize();
1814
+
1815
+ return data;
1816
+ }
1817
+
1818
+ function isCancel(value) {
1819
+ return !!(value && value.__CANCEL__);
1820
+ }
1821
+
1822
+ /**
1823
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
1824
+ *
1825
+ * @param {string=} message The message.
1826
+ * @param {Object=} config The config.
1827
+ * @param {Object=} request The request.
1828
+ *
1829
+ * @returns {CanceledError} The created error.
1830
+ */
1831
+ function CanceledError(message, config, request) {
1832
+ // eslint-disable-next-line no-eq-null,eqeqeq
1833
+ AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1834
+ this.name = 'CanceledError';
1835
+ }
1836
+
1837
+ utils.inherits(CanceledError, AxiosError, {
1838
+ __CANCEL__: true
1839
+ });
1840
+
1841
+ /**
1842
+ * Resolve or reject a Promise based on response status.
1843
+ *
1844
+ * @param {Function} resolve A function that resolves the promise.
1845
+ * @param {Function} reject A function that rejects the promise.
1846
+ * @param {object} response The response.
1847
+ *
1848
+ * @returns {object} The response.
1849
+ */
1850
+ function settle(resolve, reject, response) {
1851
+ const validateStatus = response.config.validateStatus;
1852
+ if (!response.status || !validateStatus || validateStatus(response.status)) {
1853
+ resolve(response);
1854
+ } else {
1855
+ reject(new AxiosError(
1856
+ 'Request failed with status code ' + response.status,
1857
+ [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1858
+ response.config,
1859
+ response.request,
1860
+ response
1861
+ ));
1862
+ }
1863
+ }
1864
+
1865
+ /**
1866
+ * Determines whether the specified URL is absolute
1867
+ *
1868
+ * @param {string} url The URL to test
1869
+ *
1870
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
1871
+ */
1872
+ function isAbsoluteURL(url) {
1873
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1874
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1875
+ // by any combination of letters, digits, plus, period, or hyphen.
1876
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1877
+ }
1878
+
1879
+ /**
1880
+ * Creates a new URL by combining the specified URLs
1881
+ *
1882
+ * @param {string} baseURL The base URL
1883
+ * @param {string} relativeURL The relative URL
1884
+ *
1885
+ * @returns {string} The combined URL
1886
+ */
1887
+ function combineURLs(baseURL, relativeURL) {
1888
+ return relativeURL
1889
+ ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1890
+ : baseURL;
1891
+ }
1892
+
1893
+ /**
1894
+ * Creates a new URL by combining the baseURL with the requestedURL,
1895
+ * only when the requestedURL is not already an absolute URL.
1896
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
1897
+ *
1898
+ * @param {string} baseURL The base URL
1899
+ * @param {string} requestedURL Absolute or relative URL to combine
1900
+ *
1901
+ * @returns {string} The combined full path
1902
+ */
1903
+ function buildFullPath(baseURL, requestedURL) {
1904
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
1905
+ return combineURLs(baseURL, requestedURL);
1906
+ }
1907
+ return requestedURL;
1908
+ }
1909
+
1910
+ const VERSION = "1.2.0";
1911
+
1912
+ function parseProtocol(url) {
1913
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1914
+ return match && match[1] || '';
1915
+ }
1916
+
1917
+ const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
1918
+
1919
+ /**
1920
+ * Parse data uri to a Buffer or Blob
1921
+ *
1922
+ * @param {String} uri
1923
+ * @param {?Boolean} asBlob
1924
+ * @param {?Object} options
1925
+ * @param {?Function} options.Blob
1926
+ *
1927
+ * @returns {Buffer|Blob}
1928
+ */
1929
+ function fromDataURI(uri, asBlob, options) {
1930
+ const _Blob = options && options.Blob || platform.classes.Blob;
1931
+ const protocol = parseProtocol(uri);
1932
+
1933
+ if (asBlob === undefined && _Blob) {
1934
+ asBlob = true;
1935
+ }
1936
+
1937
+ if (protocol === 'data') {
1938
+ uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
1939
+
1940
+ const match = DATA_URL_PATTERN.exec(uri);
1941
+
1942
+ if (!match) {
1943
+ throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
1734
1944
  }
1735
1945
 
1736
- utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1946
+ const mime = match[1];
1947
+ const isBase64 = match[2];
1948
+ const body = match[3];
1949
+ const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
1737
1950
 
1738
- return this;
1739
- }
1740
- }
1951
+ if (asBlob) {
1952
+ if (!_Blob) {
1953
+ throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
1954
+ }
1741
1955
 
1742
- AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1956
+ return new _Blob([buffer], {type: mime});
1957
+ }
1743
1958
 
1744
- utils.freezeMethods(AxiosHeaders.prototype);
1745
- utils.freezeMethods(AxiosHeaders);
1959
+ return buffer;
1960
+ }
1746
1961
 
1747
- const AxiosHeaders$1 = AxiosHeaders;
1962
+ throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
1963
+ }
1748
1964
 
1749
1965
  /**
1750
1966
  * Throttle decorator
@@ -2093,8 +2309,10 @@ function setProxy(options, configProxy, location) {
2093
2309
  };
2094
2310
  }
2095
2311
 
2312
+ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
2313
+
2096
2314
  /*eslint consistent-return:0*/
2097
- function httpAdapter(config) {
2315
+ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2098
2316
  return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
2099
2317
  let data = config.data;
2100
2318
  const responseType = config.responseType;
@@ -2364,6 +2582,23 @@ function httpAdapter(config) {
2364
2582
 
2365
2583
  const streams = [res];
2366
2584
 
2585
+ const responseLength = +res.headers['content-length'];
2586
+
2587
+ if (onDownloadProgress) {
2588
+ const transformStream = new AxiosTransformStream$1({
2589
+ length: utils.toFiniteNumber(responseLength),
2590
+ maxRate: utils.toFiniteNumber(maxDownloadRate)
2591
+ });
2592
+
2593
+ onDownloadProgress && transformStream.on('progress', progress => {
2594
+ onDownloadProgress(Object.assign(progress, {
2595
+ download: true
2596
+ }));
2597
+ });
2598
+
2599
+ streams.push(transformStream);
2600
+ }
2601
+
2367
2602
  // uncompress the response body transparently if required
2368
2603
  let responseStream = res;
2369
2604
 
@@ -2374,7 +2609,7 @@ function httpAdapter(config) {
2374
2609
  if (config.decompress !== false) {
2375
2610
  // if no content, but headers still say that it is encoded,
2376
2611
  // remove the header not confuse downstream operations
2377
- if (data && data.length === 0 && res.headers['content-encoding']) {
2612
+ if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
2378
2613
  delete res.headers['content-encoding'];
2379
2614
  }
2380
2615
 
@@ -2397,23 +2632,6 @@ function httpAdapter(config) {
2397
2632
  }
2398
2633
  }
2399
2634
 
2400
- if (onDownloadProgress) {
2401
- const responseLength = +res.headers['content-length'];
2402
-
2403
- const transformStream = new AxiosTransformStream$1({
2404
- length: utils.toFiniteNumber(responseLength),
2405
- maxRate: utils.toFiniteNumber(maxDownloadRate)
2406
- });
2407
-
2408
- onDownloadProgress && transformStream.on('progress', progress => {
2409
- onDownloadProgress(Object.assign(progress, {
2410
- download: true
2411
- }));
2412
- });
2413
-
2414
- streams.push(transformStream);
2415
- }
2416
-
2417
2635
  responseStream = streams.length > 1 ? stream__default["default"].pipeline(streams, utils.noop) : streams[0];
2418
2636
 
2419
2637
  const offListeners = stream__default["default"].finished(responseStream, () => {
@@ -2577,7 +2795,7 @@ function httpAdapter(config) {
2577
2795
  req.end(data);
2578
2796
  }
2579
2797
  });
2580
- }
2798
+ };
2581
2799
 
2582
2800
  const cookies = platform.isStandardBrowserEnv ?
2583
2801
 
@@ -2719,7 +2937,9 @@ function progressEventReducer(listener, isDownloadStream) {
2719
2937
  };
2720
2938
  }
2721
2939
 
2722
- function xhrAdapter(config) {
2940
+ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2941
+
2942
+ const xhrAdapter = isXHRAdapterSupported && function (config) {
2723
2943
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2724
2944
  let requestData = config.data;
2725
2945
  const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
@@ -2920,240 +3140,63 @@ function xhrAdapter(config) {
2920
3140
  // Send the request
2921
3141
  request.send(requestData || null);
2922
3142
  });
2923
- }
3143
+ };
2924
3144
 
2925
- const adapters = {
3145
+ const knownAdapters = {
2926
3146
  http: httpAdapter,
2927
3147
  xhr: xhrAdapter
2928
3148
  };
2929
3149
 
2930
- const adapters$1 = {
2931
- getAdapter: (nameOrAdapter) => {
2932
- if(utils.isString(nameOrAdapter)){
2933
- const adapter = adapters[nameOrAdapter];
2934
-
2935
- if (!nameOrAdapter) {
2936
- throw Error(
2937
- utils.hasOwnProp(nameOrAdapter) ?
2938
- `Adapter '${nameOrAdapter}' is not available in the build` :
2939
- `Can not resolve adapter '${nameOrAdapter}'`
2940
- );
2941
- }
2942
-
2943
- return adapter
2944
- }
2945
-
2946
- if (!utils.isFunction(nameOrAdapter)) {
2947
- throw new TypeError('adapter is not a function');
2948
- }
2949
-
2950
- return nameOrAdapter;
2951
- },
2952
- adapters
2953
- };
2954
-
2955
- const DEFAULT_CONTENT_TYPE = {
2956
- 'Content-Type': undefined
2957
- };
2958
-
2959
- /**
2960
- * If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
2961
- * adapter
2962
- *
2963
- * @returns {Function}
2964
- */
2965
- function getDefaultAdapter() {
2966
- let adapter;
2967
- if (typeof XMLHttpRequest !== 'undefined') {
2968
- // For browsers use XHR adapter
2969
- adapter = adapters$1.getAdapter('xhr');
2970
- } else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
2971
- // For node use HTTP adapter
2972
- adapter = adapters$1.getAdapter('http');
2973
- }
2974
- return adapter;
2975
- }
2976
-
2977
- /**
2978
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
2979
- * of the input
2980
- *
2981
- * @param {any} rawValue - The value to be stringified.
2982
- * @param {Function} parser - A function that parses a string into a JavaScript object.
2983
- * @param {Function} encoder - A function that takes a value and returns a string.
2984
- *
2985
- * @returns {string} A stringified version of the rawValue.
2986
- */
2987
- function stringifySafely(rawValue, parser, encoder) {
2988
- if (utils.isString(rawValue)) {
3150
+ utils.forEach(knownAdapters, (fn, value) => {
3151
+ if(fn) {
2989
3152
  try {
2990
- (parser || JSON.parse)(rawValue);
2991
- return utils.trim(rawValue);
3153
+ Object.defineProperty(fn, 'name', {value});
2992
3154
  } catch (e) {
2993
- if (e.name !== 'SyntaxError') {
2994
- throw e;
2995
- }
3155
+ // eslint-disable-next-line no-empty
2996
3156
  }
3157
+ Object.defineProperty(fn, 'adapterName', {value});
2997
3158
  }
3159
+ });
2998
3160
 
2999
- return (encoder || JSON.stringify)(rawValue);
3000
- }
3001
-
3002
- const defaults = {
3003
-
3004
- transitional: transitionalDefaults,
3005
-
3006
- adapter: getDefaultAdapter(),
3007
-
3008
- transformRequest: [function transformRequest(data, headers) {
3009
- const contentType = headers.getContentType() || '';
3010
- const hasJSONContentType = contentType.indexOf('application/json') > -1;
3011
- const isObjectPayload = utils.isObject(data);
3012
-
3013
- if (isObjectPayload && utils.isHTMLForm(data)) {
3014
- data = new FormData(data);
3015
- }
3161
+ const adapters = {
3162
+ getAdapter: (adapters) => {
3163
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
3016
3164
 
3017
- const isFormData = utils.isFormData(data);
3165
+ const {length} = adapters;
3166
+ let nameOrAdapter;
3167
+ let adapter;
3018
3168
 
3019
- if (isFormData) {
3020
- if (!hasJSONContentType) {
3021
- return data;
3169
+ for (let i = 0; i < length; i++) {
3170
+ nameOrAdapter = adapters[i];
3171
+ if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
3172
+ break;
3022
3173
  }
3023
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
3024
- }
3025
-
3026
- if (utils.isArrayBuffer(data) ||
3027
- utils.isBuffer(data) ||
3028
- utils.isStream(data) ||
3029
- utils.isFile(data) ||
3030
- utils.isBlob(data)
3031
- ) {
3032
- return data;
3033
- }
3034
- if (utils.isArrayBufferView(data)) {
3035
- return data.buffer;
3036
- }
3037
- if (utils.isURLSearchParams(data)) {
3038
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
3039
- return data.toString();
3040
3174
  }
3041
3175
 
3042
- let isFileList;
3043
-
3044
- if (isObjectPayload) {
3045
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
3046
- return toURLEncodedForm(data, this.formSerializer).toString();
3047
- }
3048
-
3049
- if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
3050
- const _FormData = this.env && this.env.FormData;
3051
-
3052
- return toFormData(
3053
- isFileList ? {'files[]': data} : data,
3054
- _FormData && new _FormData(),
3055
- this.formSerializer
3176
+ if (!adapter) {
3177
+ if (adapter === false) {
3178
+ throw new AxiosError(
3179
+ `Adapter ${nameOrAdapter} is not supported by the environment`,
3180
+ 'ERR_NOT_SUPPORT'
3056
3181
  );
3057
3182
  }
3058
- }
3059
3183
 
3060
- if (isObjectPayload || hasJSONContentType ) {
3061
- headers.setContentType('application/json', false);
3062
- return stringifySafely(data);
3184
+ throw new Error(
3185
+ utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
3186
+ `Adapter '${nameOrAdapter}' is not available in the build` :
3187
+ `Unknown adapter '${nameOrAdapter}'`
3188
+ );
3063
3189
  }
3064
3190
 
3065
- return data;
3066
- }],
3067
-
3068
- transformResponse: [function transformResponse(data) {
3069
- const transitional = this.transitional || defaults.transitional;
3070
- const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
3071
- const JSONRequested = this.responseType === 'json';
3072
-
3073
- if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
3074
- const silentJSONParsing = transitional && transitional.silentJSONParsing;
3075
- const strictJSONParsing = !silentJSONParsing && JSONRequested;
3076
-
3077
- try {
3078
- return JSON.parse(data);
3079
- } catch (e) {
3080
- if (strictJSONParsing) {
3081
- if (e.name === 'SyntaxError') {
3082
- throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
3083
- }
3084
- throw e;
3085
- }
3086
- }
3191
+ if (!utils.isFunction(adapter)) {
3192
+ throw new TypeError('adapter is not a function');
3087
3193
  }
3088
3194
 
3089
- return data;
3090
- }],
3091
-
3092
- /**
3093
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
3094
- * timeout is not created.
3095
- */
3096
- timeout: 0,
3097
-
3098
- xsrfCookieName: 'XSRF-TOKEN',
3099
- xsrfHeaderName: 'X-XSRF-TOKEN',
3100
-
3101
- maxContentLength: -1,
3102
- maxBodyLength: -1,
3103
-
3104
- env: {
3105
- FormData: platform.classes.FormData,
3106
- Blob: platform.classes.Blob
3107
- },
3108
-
3109
- validateStatus: function validateStatus(status) {
3110
- return status >= 200 && status < 300;
3195
+ return adapter;
3111
3196
  },
3112
-
3113
- headers: {
3114
- common: {
3115
- 'Accept': 'application/json, text/plain, */*'
3116
- }
3117
- }
3197
+ adapters: knownAdapters
3118
3198
  };
3119
3199
 
3120
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
3121
- defaults.headers[method] = {};
3122
- });
3123
-
3124
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3125
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
3126
- });
3127
-
3128
- const defaults$1 = defaults;
3129
-
3130
- /**
3131
- * Transform the data for a request or a response
3132
- *
3133
- * @param {Array|Function} fns A single function or Array of functions
3134
- * @param {?Object} response The response object
3135
- *
3136
- * @returns {*} The resulting transformed data
3137
- */
3138
- function transformData(fns, response) {
3139
- const config = this || defaults$1;
3140
- const context = response || config;
3141
- const headers = AxiosHeaders$1.from(context.headers);
3142
- let data = context.data;
3143
-
3144
- utils.forEach(fns, function transform(fn) {
3145
- data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
3146
- });
3147
-
3148
- headers.normalize();
3149
-
3150
- return data;
3151
- }
3152
-
3153
- function isCancel(value) {
3154
- return !!(value && value.__CANCEL__);
3155
- }
3156
-
3157
3200
  /**
3158
3201
  * Throws a `CanceledError` if cancellation has been requested.
3159
3202
  *
@@ -3193,7 +3236,7 @@ function dispatchRequest(config) {
3193
3236
  config.headers.setContentType('application/x-www-form-urlencoded', false);
3194
3237
  }
3195
3238
 
3196
- const adapter = config.adapter || defaults$1.adapter;
3239
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3197
3240
 
3198
3241
  return adapter(config).then(function onAdapterResolution(response) {
3199
3242
  throwIfCancellationRequested(config);