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.

package/dist/esm/axios.js CHANGED
@@ -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
  function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -595,6 +595,37 @@ const toFiniteNumber = (value, defaultValue) => {
595
595
  return Number.isFinite(value) ? value : defaultValue;
596
596
  };
597
597
 
598
+ const toJSONObject = (obj) => {
599
+ const stack = new Array(10);
600
+
601
+ const visit = (source, i) => {
602
+
603
+ if (isObject(source)) {
604
+ if (stack.indexOf(source) >= 0) {
605
+ return;
606
+ }
607
+
608
+ if(!('toJSON' in source)) {
609
+ stack[i] = source;
610
+ const target = isArray(source) ? [] : {};
611
+
612
+ forEach(source, (value, key) => {
613
+ const reducedValue = visit(value, i + 1);
614
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
615
+ });
616
+
617
+ stack[i] = undefined;
618
+
619
+ return target;
620
+ }
621
+ }
622
+
623
+ return source;
624
+ };
625
+
626
+ return visit(obj, 0);
627
+ };
628
+
598
629
  const utils = {
599
630
  isArray,
600
631
  isArrayBuffer,
@@ -640,7 +671,8 @@ const utils = {
640
671
  toFiniteNumber,
641
672
  findKey,
642
673
  global: _global,
643
- isContextDefined
674
+ isContextDefined,
675
+ toJSONObject
644
676
  };
645
677
 
646
678
  /**
@@ -686,7 +718,7 @@ utils.inherits(AxiosError$1, Error, {
686
718
  columnNumber: this.columnNumber,
687
719
  stack: this.stack,
688
720
  // Axios
689
- config: this.config,
721
+ config: utils.toJSONObject(this.config),
690
722
  code: this.code,
691
723
  status: this.response && this.response.status ? this.response.status : null
692
724
  };
@@ -1296,209 +1328,162 @@ function formDataToJSON(formData) {
1296
1328
  return null;
1297
1329
  }
1298
1330
 
1331
+ const DEFAULT_CONTENT_TYPE = {
1332
+ 'Content-Type': undefined
1333
+ };
1334
+
1299
1335
  /**
1300
- * Resolve or reject a Promise based on response status.
1336
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1337
+ * of the input
1301
1338
  *
1302
- * @param {Function} resolve A function that resolves the promise.
1303
- * @param {Function} reject A function that rejects the promise.
1304
- * @param {object} response The response.
1339
+ * @param {any} rawValue - The value to be stringified.
1340
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
1341
+ * @param {Function} encoder - A function that takes a value and returns a string.
1305
1342
  *
1306
- * @returns {object} The response.
1343
+ * @returns {string} A stringified version of the rawValue.
1307
1344
  */
1308
- function settle(resolve, reject, response) {
1309
- const validateStatus = response.config.validateStatus;
1310
- if (!response.status || !validateStatus || validateStatus(response.status)) {
1311
- resolve(response);
1312
- } else {
1313
- reject(new AxiosError$1(
1314
- 'Request failed with status code ' + response.status,
1315
- [AxiosError$1.ERR_BAD_REQUEST, AxiosError$1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1316
- response.config,
1317
- response.request,
1318
- response
1319
- ));
1345
+ function stringifySafely(rawValue, parser, encoder) {
1346
+ if (utils.isString(rawValue)) {
1347
+ try {
1348
+ (parser || JSON.parse)(rawValue);
1349
+ return utils.trim(rawValue);
1350
+ } catch (e) {
1351
+ if (e.name !== 'SyntaxError') {
1352
+ throw e;
1353
+ }
1354
+ }
1320
1355
  }
1356
+
1357
+ return (encoder || JSON.stringify)(rawValue);
1321
1358
  }
1322
1359
 
1323
- const cookies = platform.isStandardBrowserEnv ?
1360
+ const defaults = {
1324
1361
 
1325
- // Standard browser envs support document.cookie
1326
- (function standardBrowserEnv() {
1327
- return {
1328
- write: function write(name, value, expires, path, domain, secure) {
1329
- const cookie = [];
1330
- cookie.push(name + '=' + encodeURIComponent(value));
1362
+ transitional: transitionalDefaults,
1331
1363
 
1332
- if (utils.isNumber(expires)) {
1333
- cookie.push('expires=' + new Date(expires).toGMTString());
1334
- }
1364
+ adapter: ['xhr', 'http'],
1335
1365
 
1336
- if (utils.isString(path)) {
1337
- cookie.push('path=' + path);
1338
- }
1366
+ transformRequest: [function transformRequest(data, headers) {
1367
+ const contentType = headers.getContentType() || '';
1368
+ const hasJSONContentType = contentType.indexOf('application/json') > -1;
1369
+ const isObjectPayload = utils.isObject(data);
1339
1370
 
1340
- if (utils.isString(domain)) {
1341
- cookie.push('domain=' + domain);
1342
- }
1371
+ if (isObjectPayload && utils.isHTMLForm(data)) {
1372
+ data = new FormData(data);
1373
+ }
1343
1374
 
1344
- if (secure === true) {
1345
- cookie.push('secure');
1346
- }
1375
+ const isFormData = utils.isFormData(data);
1347
1376
 
1348
- document.cookie = cookie.join('; ');
1349
- },
1377
+ if (isFormData) {
1378
+ if (!hasJSONContentType) {
1379
+ return data;
1380
+ }
1381
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1382
+ }
1350
1383
 
1351
- read: function read(name) {
1352
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1353
- return (match ? decodeURIComponent(match[3]) : null);
1354
- },
1384
+ if (utils.isArrayBuffer(data) ||
1385
+ utils.isBuffer(data) ||
1386
+ utils.isStream(data) ||
1387
+ utils.isFile(data) ||
1388
+ utils.isBlob(data)
1389
+ ) {
1390
+ return data;
1391
+ }
1392
+ if (utils.isArrayBufferView(data)) {
1393
+ return data.buffer;
1394
+ }
1395
+ if (utils.isURLSearchParams(data)) {
1396
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1397
+ return data.toString();
1398
+ }
1355
1399
 
1356
- remove: function remove(name) {
1357
- this.write(name, '', Date.now() - 86400000);
1358
- }
1359
- };
1360
- })() :
1400
+ let isFileList;
1361
1401
 
1362
- // Non standard browser env (web workers, react-native) lack needed support.
1363
- (function nonStandardBrowserEnv() {
1364
- return {
1365
- write: function write() {},
1366
- read: function read() { return null; },
1367
- remove: function remove() {}
1368
- };
1369
- })();
1402
+ if (isObjectPayload) {
1403
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1404
+ return toURLEncodedForm(data, this.formSerializer).toString();
1405
+ }
1370
1406
 
1371
- /**
1372
- * Determines whether the specified URL is absolute
1373
- *
1374
- * @param {string} url The URL to test
1375
- *
1376
- * @returns {boolean} True if the specified URL is absolute, otherwise false
1377
- */
1378
- function isAbsoluteURL(url) {
1379
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1380
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1381
- // by any combination of letters, digits, plus, period, or hyphen.
1382
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1383
- }
1407
+ if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1408
+ const _FormData = this.env && this.env.FormData;
1384
1409
 
1385
- /**
1386
- * Creates a new URL by combining the specified URLs
1387
- *
1388
- * @param {string} baseURL The base URL
1389
- * @param {string} relativeURL The relative URL
1390
- *
1391
- * @returns {string} The combined URL
1392
- */
1393
- function combineURLs(baseURL, relativeURL) {
1394
- return relativeURL
1395
- ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1396
- : baseURL;
1397
- }
1410
+ return toFormData$1(
1411
+ isFileList ? {'files[]': data} : data,
1412
+ _FormData && new _FormData(),
1413
+ this.formSerializer
1414
+ );
1415
+ }
1416
+ }
1398
1417
 
1399
- /**
1400
- * Creates a new URL by combining the baseURL with the requestedURL,
1401
- * only when the requestedURL is not already an absolute URL.
1402
- * If the requestURL is absolute, this function returns the requestedURL untouched.
1403
- *
1404
- * @param {string} baseURL The base URL
1405
- * @param {string} requestedURL Absolute or relative URL to combine
1406
- *
1407
- * @returns {string} The combined full path
1408
- */
1409
- function buildFullPath(baseURL, requestedURL) {
1410
- if (baseURL && !isAbsoluteURL(requestedURL)) {
1411
- return combineURLs(baseURL, requestedURL);
1412
- }
1413
- return requestedURL;
1414
- }
1418
+ if (isObjectPayload || hasJSONContentType ) {
1419
+ headers.setContentType('application/json', false);
1420
+ return stringifySafely(data);
1421
+ }
1415
1422
 
1416
- const isURLSameOrigin = platform.isStandardBrowserEnv ?
1423
+ return data;
1424
+ }],
1417
1425
 
1418
- // Standard browser envs have full support of the APIs needed to test
1419
- // whether the request URL is of the same origin as current location.
1420
- (function standardBrowserEnv() {
1421
- const msie = /(msie|trident)/i.test(navigator.userAgent);
1422
- const urlParsingNode = document.createElement('a');
1423
- let originURL;
1426
+ transformResponse: [function transformResponse(data) {
1427
+ const transitional = this.transitional || defaults.transitional;
1428
+ const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1429
+ const JSONRequested = this.responseType === 'json';
1424
1430
 
1425
- /**
1426
- * Parse a URL to discover it's components
1427
- *
1428
- * @param {String} url The URL to be parsed
1429
- * @returns {Object}
1430
- */
1431
- function resolveURL(url) {
1432
- let href = url;
1431
+ if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1432
+ const silentJSONParsing = transitional && transitional.silentJSONParsing;
1433
+ const strictJSONParsing = !silentJSONParsing && JSONRequested;
1433
1434
 
1434
- if (msie) {
1435
- // IE needs attribute set twice to normalize properties
1436
- urlParsingNode.setAttribute('href', href);
1437
- href = urlParsingNode.href;
1435
+ try {
1436
+ return JSON.parse(data);
1437
+ } catch (e) {
1438
+ if (strictJSONParsing) {
1439
+ if (e.name === 'SyntaxError') {
1440
+ throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
1441
+ }
1442
+ throw e;
1443
+ }
1438
1444
  }
1445
+ }
1439
1446
 
1440
- urlParsingNode.setAttribute('href', href);
1447
+ return data;
1448
+ }],
1441
1449
 
1442
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
1443
- return {
1444
- href: urlParsingNode.href,
1445
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
1446
- host: urlParsingNode.host,
1447
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
1448
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
1449
- hostname: urlParsingNode.hostname,
1450
- port: urlParsingNode.port,
1451
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
1452
- urlParsingNode.pathname :
1453
- '/' + urlParsingNode.pathname
1454
- };
1455
- }
1450
+ /**
1451
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
1452
+ * timeout is not created.
1453
+ */
1454
+ timeout: 0,
1456
1455
 
1457
- originURL = resolveURL(window.location.href);
1456
+ xsrfCookieName: 'XSRF-TOKEN',
1457
+ xsrfHeaderName: 'X-XSRF-TOKEN',
1458
1458
 
1459
- /**
1460
- * Determine if a URL shares the same origin as the current location
1461
- *
1462
- * @param {String} requestURL The URL to test
1463
- * @returns {boolean} True if URL shares the same origin, otherwise false
1464
- */
1465
- return function isURLSameOrigin(requestURL) {
1466
- const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
1467
- return (parsed.protocol === originURL.protocol &&
1468
- parsed.host === originURL.host);
1469
- };
1470
- })() :
1459
+ maxContentLength: -1,
1460
+ maxBodyLength: -1,
1471
1461
 
1472
- // Non standard browser envs (web workers, react-native) lack needed support.
1473
- (function nonStandardBrowserEnv() {
1474
- return function isURLSameOrigin() {
1475
- return true;
1476
- };
1477
- })();
1462
+ env: {
1463
+ FormData: platform.classes.FormData,
1464
+ Blob: platform.classes.Blob
1465
+ },
1478
1466
 
1479
- /**
1480
- * A `CanceledError` is an object that is thrown when an operation is canceled.
1481
- *
1482
- * @param {string=} message The message.
1483
- * @param {Object=} config The config.
1484
- * @param {Object=} request The request.
1485
- *
1486
- * @returns {CanceledError} The created error.
1487
- */
1488
- function CanceledError$1(message, config, request) {
1489
- // eslint-disable-next-line no-eq-null,eqeqeq
1490
- AxiosError$1.call(this, message == null ? 'canceled' : message, AxiosError$1.ERR_CANCELED, config, request);
1491
- this.name = 'CanceledError';
1492
- }
1467
+ validateStatus: function validateStatus(status) {
1468
+ return status >= 200 && status < 300;
1469
+ },
1493
1470
 
1494
- utils.inherits(CanceledError$1, AxiosError$1, {
1495
- __CANCEL__: true
1471
+ headers: {
1472
+ common: {
1473
+ 'Accept': 'application/json, text/plain, */*'
1474
+ }
1475
+ }
1476
+ };
1477
+
1478
+ utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1479
+ defaults.headers[method] = {};
1496
1480
  });
1497
1481
 
1498
- function parseProtocol(url) {
1499
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1500
- return match && match[1] || '';
1501
- }
1482
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1483
+ defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1484
+ });
1485
+
1486
+ const defaults$1 = defaults;
1502
1487
 
1503
1488
  // RawAxiosHeaders whose duplicates are ignored by node
1504
1489
  // c.f. https://nodejs.org/api/http.html#http_message_headers
@@ -1822,6 +1807,240 @@ utils.freezeMethods(AxiosHeaders$1);
1822
1807
 
1823
1808
  const AxiosHeaders$2 = AxiosHeaders$1;
1824
1809
 
1810
+ /**
1811
+ * Transform the data for a request or a response
1812
+ *
1813
+ * @param {Array|Function} fns A single function or Array of functions
1814
+ * @param {?Object} response The response object
1815
+ *
1816
+ * @returns {*} The resulting transformed data
1817
+ */
1818
+ function transformData(fns, response) {
1819
+ const config = this || defaults$1;
1820
+ const context = response || config;
1821
+ const headers = AxiosHeaders$2.from(context.headers);
1822
+ let data = context.data;
1823
+
1824
+ utils.forEach(fns, function transform(fn) {
1825
+ data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
1826
+ });
1827
+
1828
+ headers.normalize();
1829
+
1830
+ return data;
1831
+ }
1832
+
1833
+ function isCancel$1(value) {
1834
+ return !!(value && value.__CANCEL__);
1835
+ }
1836
+
1837
+ /**
1838
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
1839
+ *
1840
+ * @param {string=} message The message.
1841
+ * @param {Object=} config The config.
1842
+ * @param {Object=} request The request.
1843
+ *
1844
+ * @returns {CanceledError} The created error.
1845
+ */
1846
+ function CanceledError$1(message, config, request) {
1847
+ // eslint-disable-next-line no-eq-null,eqeqeq
1848
+ AxiosError$1.call(this, message == null ? 'canceled' : message, AxiosError$1.ERR_CANCELED, config, request);
1849
+ this.name = 'CanceledError';
1850
+ }
1851
+
1852
+ utils.inherits(CanceledError$1, AxiosError$1, {
1853
+ __CANCEL__: true
1854
+ });
1855
+
1856
+ // eslint-disable-next-line strict
1857
+ const httpAdapter = null;
1858
+
1859
+ /**
1860
+ * Resolve or reject a Promise based on response status.
1861
+ *
1862
+ * @param {Function} resolve A function that resolves the promise.
1863
+ * @param {Function} reject A function that rejects the promise.
1864
+ * @param {object} response The response.
1865
+ *
1866
+ * @returns {object} The response.
1867
+ */
1868
+ function settle(resolve, reject, response) {
1869
+ const validateStatus = response.config.validateStatus;
1870
+ if (!response.status || !validateStatus || validateStatus(response.status)) {
1871
+ resolve(response);
1872
+ } else {
1873
+ reject(new AxiosError$1(
1874
+ 'Request failed with status code ' + response.status,
1875
+ [AxiosError$1.ERR_BAD_REQUEST, AxiosError$1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1876
+ response.config,
1877
+ response.request,
1878
+ response
1879
+ ));
1880
+ }
1881
+ }
1882
+
1883
+ const cookies = platform.isStandardBrowserEnv ?
1884
+
1885
+ // Standard browser envs support document.cookie
1886
+ (function standardBrowserEnv() {
1887
+ return {
1888
+ write: function write(name, value, expires, path, domain, secure) {
1889
+ const cookie = [];
1890
+ cookie.push(name + '=' + encodeURIComponent(value));
1891
+
1892
+ if (utils.isNumber(expires)) {
1893
+ cookie.push('expires=' + new Date(expires).toGMTString());
1894
+ }
1895
+
1896
+ if (utils.isString(path)) {
1897
+ cookie.push('path=' + path);
1898
+ }
1899
+
1900
+ if (utils.isString(domain)) {
1901
+ cookie.push('domain=' + domain);
1902
+ }
1903
+
1904
+ if (secure === true) {
1905
+ cookie.push('secure');
1906
+ }
1907
+
1908
+ document.cookie = cookie.join('; ');
1909
+ },
1910
+
1911
+ read: function read(name) {
1912
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1913
+ return (match ? decodeURIComponent(match[3]) : null);
1914
+ },
1915
+
1916
+ remove: function remove(name) {
1917
+ this.write(name, '', Date.now() - 86400000);
1918
+ }
1919
+ };
1920
+ })() :
1921
+
1922
+ // Non standard browser env (web workers, react-native) lack needed support.
1923
+ (function nonStandardBrowserEnv() {
1924
+ return {
1925
+ write: function write() {},
1926
+ read: function read() { return null; },
1927
+ remove: function remove() {}
1928
+ };
1929
+ })();
1930
+
1931
+ /**
1932
+ * Determines whether the specified URL is absolute
1933
+ *
1934
+ * @param {string} url The URL to test
1935
+ *
1936
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
1937
+ */
1938
+ function isAbsoluteURL(url) {
1939
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1940
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1941
+ // by any combination of letters, digits, plus, period, or hyphen.
1942
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1943
+ }
1944
+
1945
+ /**
1946
+ * Creates a new URL by combining the specified URLs
1947
+ *
1948
+ * @param {string} baseURL The base URL
1949
+ * @param {string} relativeURL The relative URL
1950
+ *
1951
+ * @returns {string} The combined URL
1952
+ */
1953
+ function combineURLs(baseURL, relativeURL) {
1954
+ return relativeURL
1955
+ ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1956
+ : baseURL;
1957
+ }
1958
+
1959
+ /**
1960
+ * Creates a new URL by combining the baseURL with the requestedURL,
1961
+ * only when the requestedURL is not already an absolute URL.
1962
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
1963
+ *
1964
+ * @param {string} baseURL The base URL
1965
+ * @param {string} requestedURL Absolute or relative URL to combine
1966
+ *
1967
+ * @returns {string} The combined full path
1968
+ */
1969
+ function buildFullPath(baseURL, requestedURL) {
1970
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
1971
+ return combineURLs(baseURL, requestedURL);
1972
+ }
1973
+ return requestedURL;
1974
+ }
1975
+
1976
+ const isURLSameOrigin = platform.isStandardBrowserEnv ?
1977
+
1978
+ // Standard browser envs have full support of the APIs needed to test
1979
+ // whether the request URL is of the same origin as current location.
1980
+ (function standardBrowserEnv() {
1981
+ const msie = /(msie|trident)/i.test(navigator.userAgent);
1982
+ const urlParsingNode = document.createElement('a');
1983
+ let originURL;
1984
+
1985
+ /**
1986
+ * Parse a URL to discover it's components
1987
+ *
1988
+ * @param {String} url The URL to be parsed
1989
+ * @returns {Object}
1990
+ */
1991
+ function resolveURL(url) {
1992
+ let href = url;
1993
+
1994
+ if (msie) {
1995
+ // IE needs attribute set twice to normalize properties
1996
+ urlParsingNode.setAttribute('href', href);
1997
+ href = urlParsingNode.href;
1998
+ }
1999
+
2000
+ urlParsingNode.setAttribute('href', href);
2001
+
2002
+ // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2003
+ return {
2004
+ href: urlParsingNode.href,
2005
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2006
+ host: urlParsingNode.host,
2007
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2008
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2009
+ hostname: urlParsingNode.hostname,
2010
+ port: urlParsingNode.port,
2011
+ pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
2012
+ urlParsingNode.pathname :
2013
+ '/' + urlParsingNode.pathname
2014
+ };
2015
+ }
2016
+
2017
+ originURL = resolveURL(window.location.href);
2018
+
2019
+ /**
2020
+ * Determine if a URL shares the same origin as the current location
2021
+ *
2022
+ * @param {String} requestURL The URL to test
2023
+ * @returns {boolean} True if URL shares the same origin, otherwise false
2024
+ */
2025
+ return function isURLSameOrigin(requestURL) {
2026
+ const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2027
+ return (parsed.protocol === originURL.protocol &&
2028
+ parsed.host === originURL.host);
2029
+ };
2030
+ })() :
2031
+
2032
+ // Non standard browser envs (web workers, react-native) lack needed support.
2033
+ (function nonStandardBrowserEnv() {
2034
+ return function isURLSameOrigin() {
2035
+ return true;
2036
+ };
2037
+ })();
2038
+
2039
+ function parseProtocol(url) {
2040
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2041
+ return match && match[1] || '';
2042
+ }
2043
+
1825
2044
  /**
1826
2045
  * Calculate data maxRate
1827
2046
  * @param {Number} [samplesCount= 10]
@@ -1903,7 +2122,9 @@ function progressEventReducer(listener, isDownloadStream) {
1903
2122
  };
1904
2123
  }
1905
2124
 
1906
- function xhrAdapter(config) {
2125
+ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2126
+
2127
+ const xhrAdapter = isXHRAdapterSupported && function (config) {
1907
2128
  return new Promise(function dispatchXhrRequest(resolve, reject) {
1908
2129
  let requestData = config.data;
1909
2130
  const requestHeaders = AxiosHeaders$2.from(config.headers).normalize();
@@ -2104,240 +2325,63 @@ function xhrAdapter(config) {
2104
2325
  // Send the request
2105
2326
  request.send(requestData || null);
2106
2327
  });
2107
- }
2108
-
2109
- const adapters = {
2110
- http: xhrAdapter,
2111
- xhr: xhrAdapter
2112
2328
  };
2113
2329
 
2114
- const adapters$1 = {
2115
- getAdapter: (nameOrAdapter) => {
2116
- if(utils.isString(nameOrAdapter)){
2117
- const adapter = adapters[nameOrAdapter];
2118
-
2119
- if (!nameOrAdapter) {
2120
- throw Error(
2121
- utils.hasOwnProp(nameOrAdapter) ?
2122
- `Adapter '${nameOrAdapter}' is not available in the build` :
2123
- `Can not resolve adapter '${nameOrAdapter}'`
2124
- );
2125
- }
2126
-
2127
- return adapter
2128
- }
2129
-
2130
- if (!utils.isFunction(nameOrAdapter)) {
2131
- throw new TypeError('adapter is not a function');
2132
- }
2133
-
2134
- return nameOrAdapter;
2135
- },
2136
- adapters
2137
- };
2138
-
2139
- const DEFAULT_CONTENT_TYPE = {
2140
- 'Content-Type': undefined
2330
+ const knownAdapters = {
2331
+ http: httpAdapter,
2332
+ xhr: xhrAdapter
2141
2333
  };
2142
2334
 
2143
- /**
2144
- * If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
2145
- * adapter
2146
- *
2147
- * @returns {Function}
2148
- */
2149
- function getDefaultAdapter() {
2150
- let adapter;
2151
- if (typeof XMLHttpRequest !== 'undefined') {
2152
- // For browsers use XHR adapter
2153
- adapter = adapters$1.getAdapter('xhr');
2154
- } else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
2155
- // For node use HTTP adapter
2156
- adapter = adapters$1.getAdapter('http');
2157
- }
2158
- return adapter;
2159
- }
2160
-
2161
- /**
2162
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
2163
- * of the input
2164
- *
2165
- * @param {any} rawValue - The value to be stringified.
2166
- * @param {Function} parser - A function that parses a string into a JavaScript object.
2167
- * @param {Function} encoder - A function that takes a value and returns a string.
2168
- *
2169
- * @returns {string} A stringified version of the rawValue.
2170
- */
2171
- function stringifySafely(rawValue, parser, encoder) {
2172
- if (utils.isString(rawValue)) {
2335
+ utils.forEach(knownAdapters, (fn, value) => {
2336
+ if(fn) {
2173
2337
  try {
2174
- (parser || JSON.parse)(rawValue);
2175
- return utils.trim(rawValue);
2338
+ Object.defineProperty(fn, 'name', {value});
2176
2339
  } catch (e) {
2177
- if (e.name !== 'SyntaxError') {
2178
- throw e;
2179
- }
2340
+ // eslint-disable-next-line no-empty
2180
2341
  }
2342
+ Object.defineProperty(fn, 'adapterName', {value});
2181
2343
  }
2344
+ });
2182
2345
 
2183
- return (encoder || JSON.stringify)(rawValue);
2184
- }
2185
-
2186
- const defaults = {
2187
-
2188
- transitional: transitionalDefaults,
2189
-
2190
- adapter: getDefaultAdapter(),
2191
-
2192
- transformRequest: [function transformRequest(data, headers) {
2193
- const contentType = headers.getContentType() || '';
2194
- const hasJSONContentType = contentType.indexOf('application/json') > -1;
2195
- const isObjectPayload = utils.isObject(data);
2196
-
2197
- if (isObjectPayload && utils.isHTMLForm(data)) {
2198
- data = new FormData(data);
2199
- }
2346
+ const adapters = {
2347
+ getAdapter: (adapters) => {
2348
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
2200
2349
 
2201
- const isFormData = utils.isFormData(data);
2350
+ const {length} = adapters;
2351
+ let nameOrAdapter;
2352
+ let adapter;
2202
2353
 
2203
- if (isFormData) {
2204
- if (!hasJSONContentType) {
2205
- return data;
2354
+ for (let i = 0; i < length; i++) {
2355
+ nameOrAdapter = adapters[i];
2356
+ if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
2357
+ break;
2206
2358
  }
2207
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
2208
- }
2209
-
2210
- if (utils.isArrayBuffer(data) ||
2211
- utils.isBuffer(data) ||
2212
- utils.isStream(data) ||
2213
- utils.isFile(data) ||
2214
- utils.isBlob(data)
2215
- ) {
2216
- return data;
2217
- }
2218
- if (utils.isArrayBufferView(data)) {
2219
- return data.buffer;
2220
2359
  }
2221
- if (utils.isURLSearchParams(data)) {
2222
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
2223
- return data.toString();
2224
- }
2225
-
2226
- let isFileList;
2227
-
2228
- if (isObjectPayload) {
2229
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
2230
- return toURLEncodedForm(data, this.formSerializer).toString();
2231
- }
2232
2360
 
2233
- if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
2234
- const _FormData = this.env && this.env.FormData;
2235
-
2236
- return toFormData$1(
2237
- isFileList ? {'files[]': data} : data,
2238
- _FormData && new _FormData(),
2239
- this.formSerializer
2361
+ if (!adapter) {
2362
+ if (adapter === false) {
2363
+ throw new AxiosError$1(
2364
+ `Adapter ${nameOrAdapter} is not supported by the environment`,
2365
+ 'ERR_NOT_SUPPORT'
2240
2366
  );
2241
2367
  }
2242
- }
2243
2368
 
2244
- if (isObjectPayload || hasJSONContentType ) {
2245
- headers.setContentType('application/json', false);
2246
- return stringifySafely(data);
2369
+ throw new Error(
2370
+ utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
2371
+ `Adapter '${nameOrAdapter}' is not available in the build` :
2372
+ `Unknown adapter '${nameOrAdapter}'`
2373
+ );
2247
2374
  }
2248
2375
 
2249
- return data;
2250
- }],
2251
-
2252
- transformResponse: [function transformResponse(data) {
2253
- const transitional = this.transitional || defaults.transitional;
2254
- const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
2255
- const JSONRequested = this.responseType === 'json';
2256
-
2257
- if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
2258
- const silentJSONParsing = transitional && transitional.silentJSONParsing;
2259
- const strictJSONParsing = !silentJSONParsing && JSONRequested;
2260
-
2261
- try {
2262
- return JSON.parse(data);
2263
- } catch (e) {
2264
- if (strictJSONParsing) {
2265
- if (e.name === 'SyntaxError') {
2266
- throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
2267
- }
2268
- throw e;
2269
- }
2270
- }
2376
+ if (!utils.isFunction(adapter)) {
2377
+ throw new TypeError('adapter is not a function');
2271
2378
  }
2272
2379
 
2273
- return data;
2274
- }],
2275
-
2276
- /**
2277
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
2278
- * timeout is not created.
2279
- */
2280
- timeout: 0,
2281
-
2282
- xsrfCookieName: 'XSRF-TOKEN',
2283
- xsrfHeaderName: 'X-XSRF-TOKEN',
2284
-
2285
- maxContentLength: -1,
2286
- maxBodyLength: -1,
2287
-
2288
- env: {
2289
- FormData: platform.classes.FormData,
2290
- Blob: platform.classes.Blob
2291
- },
2292
-
2293
- validateStatus: function validateStatus(status) {
2294
- return status >= 200 && status < 300;
2380
+ return adapter;
2295
2381
  },
2296
-
2297
- headers: {
2298
- common: {
2299
- 'Accept': 'application/json, text/plain, */*'
2300
- }
2301
- }
2382
+ adapters: knownAdapters
2302
2383
  };
2303
2384
 
2304
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
2305
- defaults.headers[method] = {};
2306
- });
2307
-
2308
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
2309
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
2310
- });
2311
-
2312
- const defaults$1 = defaults;
2313
-
2314
- /**
2315
- * Transform the data for a request or a response
2316
- *
2317
- * @param {Array|Function} fns A single function or Array of functions
2318
- * @param {?Object} response The response object
2319
- *
2320
- * @returns {*} The resulting transformed data
2321
- */
2322
- function transformData(fns, response) {
2323
- const config = this || defaults$1;
2324
- const context = response || config;
2325
- const headers = AxiosHeaders$2.from(context.headers);
2326
- let data = context.data;
2327
-
2328
- utils.forEach(fns, function transform(fn) {
2329
- data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
2330
- });
2331
-
2332
- headers.normalize();
2333
-
2334
- return data;
2335
- }
2336
-
2337
- function isCancel$1(value) {
2338
- return !!(value && value.__CANCEL__);
2339
- }
2340
-
2341
2385
  /**
2342
2386
  * Throws a `CanceledError` if cancellation has been requested.
2343
2387
  *
@@ -2377,7 +2421,7 @@ function dispatchRequest(config) {
2377
2421
  config.headers.setContentType('application/x-www-form-urlencoded', false);
2378
2422
  }
2379
2423
 
2380
- const adapter = config.adapter || defaults$1.adapter;
2424
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
2381
2425
 
2382
2426
  return adapter(config).then(function onAdapterResolution(response) {
2383
2427
  throwIfCancellationRequested(config);
@@ -2512,7 +2556,7 @@ function mergeConfig(config1, config2) {
2512
2556
  return config;
2513
2557
  }
2514
2558
 
2515
- const VERSION$1 = "1.2.0-alpha.1";
2559
+ const VERSION$1 = "1.2.0";
2516
2560
 
2517
2561
  const validators$1 = {};
2518
2562