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