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