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.
- package/CHANGELOG.md +48 -1
- package/README.md +6 -5
- package/dist/axios.js +401 -351
- 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 +470 -404
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +482 -415
- 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 +422 -368
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +3 -0
- package/index.d.ts +18 -4
- package/index.js +4 -2
- package/lib/adapters/adapters.js +59 -0
- package/lib/adapters/http.js +36 -26
- package/lib/adapters/xhr.js +5 -3
- package/lib/axios.js +3 -0
- package/lib/core/AxiosError.js +1 -1
- package/lib/core/dispatchRequest.js +3 -2
- package/lib/defaults/index.js +1 -20
- package/lib/env/data.js +1 -1
- package/lib/helpers/speedometer.js +1 -1
- package/lib/platform/browser/index.js +19 -0
- package/lib/utils.js +33 -1
- package/package.json +2 -2
- package/lib/adapters/index.js +0 -33
package/dist/axios.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// Axios v1.2.
|
1
|
+
// Axios v1.2.1 Copyright (c) 2022 Matt Zabriskie and contributors
|
2
2
|
(function (global, factory) {
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
4
4
|
typeof define === 'function' && define.amd ? define(factory) :
|
@@ -666,6 +666,28 @@
|
|
666
666
|
value = +value;
|
667
667
|
return Number.isFinite(value) ? value : defaultValue;
|
668
668
|
};
|
669
|
+
var toJSONObject = function toJSONObject(obj) {
|
670
|
+
var stack = new Array(10);
|
671
|
+
var visit = function visit(source, i) {
|
672
|
+
if (isObject(source)) {
|
673
|
+
if (stack.indexOf(source) >= 0) {
|
674
|
+
return;
|
675
|
+
}
|
676
|
+
if (!('toJSON' in source)) {
|
677
|
+
stack[i] = source;
|
678
|
+
var target = isArray(source) ? [] : {};
|
679
|
+
forEach(source, function (value, key) {
|
680
|
+
var reducedValue = visit(value, i + 1);
|
681
|
+
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
682
|
+
});
|
683
|
+
stack[i] = undefined;
|
684
|
+
return target;
|
685
|
+
}
|
686
|
+
}
|
687
|
+
return source;
|
688
|
+
};
|
689
|
+
return visit(obj, 0);
|
690
|
+
};
|
669
691
|
var utils = {
|
670
692
|
isArray: isArray,
|
671
693
|
isArrayBuffer: isArrayBuffer,
|
@@ -712,7 +734,8 @@
|
|
712
734
|
toFiniteNumber: toFiniteNumber,
|
713
735
|
findKey: findKey,
|
714
736
|
global: _global,
|
715
|
-
isContextDefined: isContextDefined
|
737
|
+
isContextDefined: isContextDefined,
|
738
|
+
toJSONObject: toJSONObject
|
716
739
|
};
|
717
740
|
|
718
741
|
/**
|
@@ -755,7 +778,7 @@
|
|
755
778
|
columnNumber: this.columnNumber,
|
756
779
|
stack: this.stack,
|
757
780
|
// Axios
|
758
|
-
config: this.config,
|
781
|
+
config: utils.toJSONObject(this.config),
|
759
782
|
code: this.code,
|
760
783
|
status: this.response && this.response.status ? this.response.status : null
|
761
784
|
};
|
@@ -1189,6 +1212,19 @@
|
|
1189
1212
|
}
|
1190
1213
|
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
1191
1214
|
}();
|
1215
|
+
|
1216
|
+
/**
|
1217
|
+
* Determine if we're running in a standard browser webWorker environment
|
1218
|
+
*
|
1219
|
+
* Although the `isStandardBrowserEnv` method indicates that
|
1220
|
+
* `allows axios to run in a web worker`, the WebWorker will still be
|
1221
|
+
* filtered out due to its judgment standard
|
1222
|
+
* `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
1223
|
+
* This leads to a problem when axios post `FormData` in webWorker
|
1224
|
+
*/
|
1225
|
+
var isStandardBrowserWebWorkerEnv = function () {
|
1226
|
+
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope && typeof self.importScripts === 'function';
|
1227
|
+
}();
|
1192
1228
|
var platform = {
|
1193
1229
|
isBrowser: true,
|
1194
1230
|
classes: {
|
@@ -1197,6 +1233,7 @@
|
|
1197
1233
|
Blob: Blob
|
1198
1234
|
},
|
1199
1235
|
isStandardBrowserEnv: isStandardBrowserEnv,
|
1236
|
+
isStandardBrowserWebWorkerEnv: isStandardBrowserWebWorkerEnv,
|
1200
1237
|
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
1201
1238
|
};
|
1202
1239
|
|
@@ -1289,185 +1326,127 @@
|
|
1289
1326
|
return null;
|
1290
1327
|
}
|
1291
1328
|
|
1329
|
+
var DEFAULT_CONTENT_TYPE = {
|
1330
|
+
'Content-Type': undefined
|
1331
|
+
};
|
1332
|
+
|
1292
1333
|
/**
|
1293
|
-
*
|
1334
|
+
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
1335
|
+
* of the input
|
1294
1336
|
*
|
1295
|
-
* @param {
|
1296
|
-
* @param {Function}
|
1297
|
-
* @param {
|
1337
|
+
* @param {any} rawValue - The value to be stringified.
|
1338
|
+
* @param {Function} parser - A function that parses a string into a JavaScript object.
|
1339
|
+
* @param {Function} encoder - A function that takes a value and returns a string.
|
1298
1340
|
*
|
1299
|
-
* @returns {
|
1341
|
+
* @returns {string} A stringified version of the rawValue.
|
1300
1342
|
*/
|
1301
|
-
function
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1343
|
+
function stringifySafely(rawValue, parser, encoder) {
|
1344
|
+
if (utils.isString(rawValue)) {
|
1345
|
+
try {
|
1346
|
+
(parser || JSON.parse)(rawValue);
|
1347
|
+
return utils.trim(rawValue);
|
1348
|
+
} catch (e) {
|
1349
|
+
if (e.name !== 'SyntaxError') {
|
1350
|
+
throw e;
|
1351
|
+
}
|
1352
|
+
}
|
1307
1353
|
}
|
1354
|
+
return (encoder || JSON.stringify)(rawValue);
|
1308
1355
|
}
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1356
|
+
var defaults = {
|
1357
|
+
transitional: transitionalDefaults,
|
1358
|
+
adapter: ['xhr', 'http'],
|
1359
|
+
transformRequest: [function transformRequest(data, headers) {
|
1360
|
+
var contentType = headers.getContentType() || '';
|
1361
|
+
var hasJSONContentType = contentType.indexOf('application/json') > -1;
|
1362
|
+
var isObjectPayload = utils.isObject(data);
|
1363
|
+
if (isObjectPayload && utils.isHTMLForm(data)) {
|
1364
|
+
data = new FormData(data);
|
1365
|
+
}
|
1366
|
+
var isFormData = utils.isFormData(data);
|
1367
|
+
if (isFormData) {
|
1368
|
+
if (!hasJSONContentType) {
|
1369
|
+
return data;
|
1319
1370
|
}
|
1320
|
-
|
1321
|
-
|
1371
|
+
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
1372
|
+
}
|
1373
|
+
if (utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data)) {
|
1374
|
+
return data;
|
1375
|
+
}
|
1376
|
+
if (utils.isArrayBufferView(data)) {
|
1377
|
+
return data.buffer;
|
1378
|
+
}
|
1379
|
+
if (utils.isURLSearchParams(data)) {
|
1380
|
+
headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
|
1381
|
+
return data.toString();
|
1382
|
+
}
|
1383
|
+
var isFileList;
|
1384
|
+
if (isObjectPayload) {
|
1385
|
+
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
|
1386
|
+
return toURLEncodedForm(data, this.formSerializer).toString();
|
1322
1387
|
}
|
1323
|
-
if (utils.
|
1324
|
-
|
1388
|
+
if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
|
1389
|
+
var _FormData = this.env && this.env.FormData;
|
1390
|
+
return toFormData(isFileList ? {
|
1391
|
+
'files[]': data
|
1392
|
+
} : data, _FormData && new _FormData(), this.formSerializer);
|
1325
1393
|
}
|
1326
|
-
|
1327
|
-
|
1394
|
+
}
|
1395
|
+
if (isObjectPayload || hasJSONContentType) {
|
1396
|
+
headers.setContentType('application/json', false);
|
1397
|
+
return stringifySafely(data);
|
1398
|
+
}
|
1399
|
+
return data;
|
1400
|
+
}],
|
1401
|
+
transformResponse: [function transformResponse(data) {
|
1402
|
+
var transitional = this.transitional || defaults.transitional;
|
1403
|
+
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
1404
|
+
var JSONRequested = this.responseType === 'json';
|
1405
|
+
if (data && utils.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
|
1406
|
+
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
1407
|
+
var strictJSONParsing = !silentJSONParsing && JSONRequested;
|
1408
|
+
try {
|
1409
|
+
return JSON.parse(data);
|
1410
|
+
} catch (e) {
|
1411
|
+
if (strictJSONParsing) {
|
1412
|
+
if (e.name === 'SyntaxError') {
|
1413
|
+
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
|
1414
|
+
}
|
1415
|
+
throw e;
|
1416
|
+
}
|
1328
1417
|
}
|
1329
|
-
document.cookie = cookie.join('; ');
|
1330
|
-
},
|
1331
|
-
read: function read(name) {
|
1332
|
-
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
1333
|
-
return match ? decodeURIComponent(match[3]) : null;
|
1334
|
-
},
|
1335
|
-
remove: function remove(name) {
|
1336
|
-
this.write(name, '', Date.now() - 86400000);
|
1337
1418
|
}
|
1338
|
-
|
1339
|
-
|
1340
|
-
// Non standard browser env (web workers, react-native) lack needed support.
|
1341
|
-
function nonStandardBrowserEnv() {
|
1342
|
-
return {
|
1343
|
-
write: function write() {},
|
1344
|
-
read: function read() {
|
1345
|
-
return null;
|
1346
|
-
},
|
1347
|
-
remove: function remove() {}
|
1348
|
-
};
|
1349
|
-
}();
|
1350
|
-
|
1351
|
-
/**
|
1352
|
-
* Determines whether the specified URL is absolute
|
1353
|
-
*
|
1354
|
-
* @param {string} url The URL to test
|
1355
|
-
*
|
1356
|
-
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
1357
|
-
*/
|
1358
|
-
function isAbsoluteURL(url) {
|
1359
|
-
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
1360
|
-
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
1361
|
-
// by any combination of letters, digits, plus, period, or hyphen.
|
1362
|
-
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
1363
|
-
}
|
1364
|
-
|
1365
|
-
/**
|
1366
|
-
* Creates a new URL by combining the specified URLs
|
1367
|
-
*
|
1368
|
-
* @param {string} baseURL The base URL
|
1369
|
-
* @param {string} relativeURL The relative URL
|
1370
|
-
*
|
1371
|
-
* @returns {string} The combined URL
|
1372
|
-
*/
|
1373
|
-
function combineURLs(baseURL, relativeURL) {
|
1374
|
-
return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
|
1375
|
-
}
|
1376
|
-
|
1377
|
-
/**
|
1378
|
-
* Creates a new URL by combining the baseURL with the requestedURL,
|
1379
|
-
* only when the requestedURL is not already an absolute URL.
|
1380
|
-
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
1381
|
-
*
|
1382
|
-
* @param {string} baseURL The base URL
|
1383
|
-
* @param {string} requestedURL Absolute or relative URL to combine
|
1384
|
-
*
|
1385
|
-
* @returns {string} The combined full path
|
1386
|
-
*/
|
1387
|
-
function buildFullPath(baseURL, requestedURL) {
|
1388
|
-
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
1389
|
-
return combineURLs(baseURL, requestedURL);
|
1390
|
-
}
|
1391
|
-
return requestedURL;
|
1392
|
-
}
|
1393
|
-
|
1394
|
-
var isURLSameOrigin = platform.isStandardBrowserEnv ?
|
1395
|
-
// Standard browser envs have full support of the APIs needed to test
|
1396
|
-
// whether the request URL is of the same origin as current location.
|
1397
|
-
function standardBrowserEnv() {
|
1398
|
-
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
1399
|
-
var urlParsingNode = document.createElement('a');
|
1400
|
-
var originURL;
|
1401
|
-
|
1419
|
+
return data;
|
1420
|
+
}],
|
1402
1421
|
/**
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1422
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
1423
|
+
* timeout is not created.
|
1424
|
+
*/
|
1425
|
+
timeout: 0,
|
1426
|
+
xsrfCookieName: 'XSRF-TOKEN',
|
1427
|
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
1428
|
+
maxContentLength: -1,
|
1429
|
+
maxBodyLength: -1,
|
1430
|
+
env: {
|
1431
|
+
FormData: platform.classes.FormData,
|
1432
|
+
Blob: platform.classes.Blob
|
1433
|
+
},
|
1434
|
+
validateStatus: function validateStatus(status) {
|
1435
|
+
return status >= 200 && status < 300;
|
1436
|
+
},
|
1437
|
+
headers: {
|
1438
|
+
common: {
|
1439
|
+
'Accept': 'application/json, text/plain, */*'
|
1414
1440
|
}
|
1415
|
-
urlParsingNode.setAttribute('href', href);
|
1416
|
-
|
1417
|
-
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
1418
|
-
return {
|
1419
|
-
href: urlParsingNode.href,
|
1420
|
-
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
1421
|
-
host: urlParsingNode.host,
|
1422
|
-
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
1423
|
-
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
1424
|
-
hostname: urlParsingNode.hostname,
|
1425
|
-
port: urlParsingNode.port,
|
1426
|
-
pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
|
1427
|
-
};
|
1428
1441
|
}
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
* Determine if a URL shares the same origin as the current location
|
1433
|
-
*
|
1434
|
-
* @param {String} requestURL The URL to test
|
1435
|
-
* @returns {boolean} True if URL shares the same origin, otherwise false
|
1436
|
-
*/
|
1437
|
-
return function isURLSameOrigin(requestURL) {
|
1438
|
-
var parsed = utils.isString(requestURL) ? resolveURL(requestURL) : requestURL;
|
1439
|
-
return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
|
1440
|
-
};
|
1441
|
-
}() :
|
1442
|
-
// Non standard browser envs (web workers, react-native) lack needed support.
|
1443
|
-
function nonStandardBrowserEnv() {
|
1444
|
-
return function isURLSameOrigin() {
|
1445
|
-
return true;
|
1446
|
-
};
|
1447
|
-
}();
|
1448
|
-
|
1449
|
-
/**
|
1450
|
-
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
1451
|
-
*
|
1452
|
-
* @param {string=} message The message.
|
1453
|
-
* @param {Object=} config The config.
|
1454
|
-
* @param {Object=} request The request.
|
1455
|
-
*
|
1456
|
-
* @returns {CanceledError} The created error.
|
1457
|
-
*/
|
1458
|
-
function CanceledError(message, config, request) {
|
1459
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
1460
|
-
AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
|
1461
|
-
this.name = 'CanceledError';
|
1462
|
-
}
|
1463
|
-
utils.inherits(CanceledError, AxiosError, {
|
1464
|
-
__CANCEL__: true
|
1442
|
+
};
|
1443
|
+
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
1444
|
+
defaults.headers[method] = {};
|
1465
1445
|
});
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
}
|
1446
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
1447
|
+
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
1448
|
+
});
|
1449
|
+
var defaults$1 = defaults;
|
1471
1450
|
|
1472
1451
|
// RawAxiosHeaders whose duplicates are ignored by node
|
1473
1452
|
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
@@ -1750,13 +1729,220 @@
|
|
1750
1729
|
utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
1751
1730
|
return this;
|
1752
1731
|
}
|
1753
|
-
}]);
|
1754
|
-
return AxiosHeaders;
|
1755
|
-
}(Symbol.iterator, Symbol.toStringTag);
|
1756
|
-
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
|
1757
|
-
utils.freezeMethods(AxiosHeaders.prototype);
|
1758
|
-
utils.freezeMethods(AxiosHeaders);
|
1759
|
-
var AxiosHeaders$1 = AxiosHeaders;
|
1732
|
+
}]);
|
1733
|
+
return AxiosHeaders;
|
1734
|
+
}(Symbol.iterator, Symbol.toStringTag);
|
1735
|
+
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
|
1736
|
+
utils.freezeMethods(AxiosHeaders.prototype);
|
1737
|
+
utils.freezeMethods(AxiosHeaders);
|
1738
|
+
var AxiosHeaders$1 = AxiosHeaders;
|
1739
|
+
|
1740
|
+
/**
|
1741
|
+
* Transform the data for a request or a response
|
1742
|
+
*
|
1743
|
+
* @param {Array|Function} fns A single function or Array of functions
|
1744
|
+
* @param {?Object} response The response object
|
1745
|
+
*
|
1746
|
+
* @returns {*} The resulting transformed data
|
1747
|
+
*/
|
1748
|
+
function transformData(fns, response) {
|
1749
|
+
var config = this || defaults$1;
|
1750
|
+
var context = response || config;
|
1751
|
+
var headers = AxiosHeaders$1.from(context.headers);
|
1752
|
+
var data = context.data;
|
1753
|
+
utils.forEach(fns, function transform(fn) {
|
1754
|
+
data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
|
1755
|
+
});
|
1756
|
+
headers.normalize();
|
1757
|
+
return data;
|
1758
|
+
}
|
1759
|
+
|
1760
|
+
function isCancel(value) {
|
1761
|
+
return !!(value && value.__CANCEL__);
|
1762
|
+
}
|
1763
|
+
|
1764
|
+
/**
|
1765
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
1766
|
+
*
|
1767
|
+
* @param {string=} message The message.
|
1768
|
+
* @param {Object=} config The config.
|
1769
|
+
* @param {Object=} request The request.
|
1770
|
+
*
|
1771
|
+
* @returns {CanceledError} The created error.
|
1772
|
+
*/
|
1773
|
+
function CanceledError(message, config, request) {
|
1774
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
1775
|
+
AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
|
1776
|
+
this.name = 'CanceledError';
|
1777
|
+
}
|
1778
|
+
utils.inherits(CanceledError, AxiosError, {
|
1779
|
+
__CANCEL__: true
|
1780
|
+
});
|
1781
|
+
|
1782
|
+
// eslint-disable-next-line strict
|
1783
|
+
var httpAdapter = null;
|
1784
|
+
|
1785
|
+
/**
|
1786
|
+
* Resolve or reject a Promise based on response status.
|
1787
|
+
*
|
1788
|
+
* @param {Function} resolve A function that resolves the promise.
|
1789
|
+
* @param {Function} reject A function that rejects the promise.
|
1790
|
+
* @param {object} response The response.
|
1791
|
+
*
|
1792
|
+
* @returns {object} The response.
|
1793
|
+
*/
|
1794
|
+
function settle(resolve, reject, response) {
|
1795
|
+
var validateStatus = response.config.validateStatus;
|
1796
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
1797
|
+
resolve(response);
|
1798
|
+
} else {
|
1799
|
+
reject(new AxiosError('Request failed with status code ' + response.status, [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response));
|
1800
|
+
}
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
var cookies = platform.isStandardBrowserEnv ?
|
1804
|
+
// Standard browser envs support document.cookie
|
1805
|
+
function standardBrowserEnv() {
|
1806
|
+
return {
|
1807
|
+
write: function write(name, value, expires, path, domain, secure) {
|
1808
|
+
var cookie = [];
|
1809
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
1810
|
+
if (utils.isNumber(expires)) {
|
1811
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
1812
|
+
}
|
1813
|
+
if (utils.isString(path)) {
|
1814
|
+
cookie.push('path=' + path);
|
1815
|
+
}
|
1816
|
+
if (utils.isString(domain)) {
|
1817
|
+
cookie.push('domain=' + domain);
|
1818
|
+
}
|
1819
|
+
if (secure === true) {
|
1820
|
+
cookie.push('secure');
|
1821
|
+
}
|
1822
|
+
document.cookie = cookie.join('; ');
|
1823
|
+
},
|
1824
|
+
read: function read(name) {
|
1825
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
1826
|
+
return match ? decodeURIComponent(match[3]) : null;
|
1827
|
+
},
|
1828
|
+
remove: function remove(name) {
|
1829
|
+
this.write(name, '', Date.now() - 86400000);
|
1830
|
+
}
|
1831
|
+
};
|
1832
|
+
}() :
|
1833
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
1834
|
+
function nonStandardBrowserEnv() {
|
1835
|
+
return {
|
1836
|
+
write: function write() {},
|
1837
|
+
read: function read() {
|
1838
|
+
return null;
|
1839
|
+
},
|
1840
|
+
remove: function remove() {}
|
1841
|
+
};
|
1842
|
+
}();
|
1843
|
+
|
1844
|
+
/**
|
1845
|
+
* Determines whether the specified URL is absolute
|
1846
|
+
*
|
1847
|
+
* @param {string} url The URL to test
|
1848
|
+
*
|
1849
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
1850
|
+
*/
|
1851
|
+
function isAbsoluteURL(url) {
|
1852
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
1853
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
1854
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
1855
|
+
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
1856
|
+
}
|
1857
|
+
|
1858
|
+
/**
|
1859
|
+
* Creates a new URL by combining the specified URLs
|
1860
|
+
*
|
1861
|
+
* @param {string} baseURL The base URL
|
1862
|
+
* @param {string} relativeURL The relative URL
|
1863
|
+
*
|
1864
|
+
* @returns {string} The combined URL
|
1865
|
+
*/
|
1866
|
+
function combineURLs(baseURL, relativeURL) {
|
1867
|
+
return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
|
1868
|
+
}
|
1869
|
+
|
1870
|
+
/**
|
1871
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
1872
|
+
* only when the requestedURL is not already an absolute URL.
|
1873
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
1874
|
+
*
|
1875
|
+
* @param {string} baseURL The base URL
|
1876
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
1877
|
+
*
|
1878
|
+
* @returns {string} The combined full path
|
1879
|
+
*/
|
1880
|
+
function buildFullPath(baseURL, requestedURL) {
|
1881
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
1882
|
+
return combineURLs(baseURL, requestedURL);
|
1883
|
+
}
|
1884
|
+
return requestedURL;
|
1885
|
+
}
|
1886
|
+
|
1887
|
+
var isURLSameOrigin = platform.isStandardBrowserEnv ?
|
1888
|
+
// Standard browser envs have full support of the APIs needed to test
|
1889
|
+
// whether the request URL is of the same origin as current location.
|
1890
|
+
function standardBrowserEnv() {
|
1891
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
1892
|
+
var urlParsingNode = document.createElement('a');
|
1893
|
+
var originURL;
|
1894
|
+
|
1895
|
+
/**
|
1896
|
+
* Parse a URL to discover it's components
|
1897
|
+
*
|
1898
|
+
* @param {String} url The URL to be parsed
|
1899
|
+
* @returns {Object}
|
1900
|
+
*/
|
1901
|
+
function resolveURL(url) {
|
1902
|
+
var href = url;
|
1903
|
+
if (msie) {
|
1904
|
+
// IE needs attribute set twice to normalize properties
|
1905
|
+
urlParsingNode.setAttribute('href', href);
|
1906
|
+
href = urlParsingNode.href;
|
1907
|
+
}
|
1908
|
+
urlParsingNode.setAttribute('href', href);
|
1909
|
+
|
1910
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
1911
|
+
return {
|
1912
|
+
href: urlParsingNode.href,
|
1913
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
1914
|
+
host: urlParsingNode.host,
|
1915
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
1916
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
1917
|
+
hostname: urlParsingNode.hostname,
|
1918
|
+
port: urlParsingNode.port,
|
1919
|
+
pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
|
1920
|
+
};
|
1921
|
+
}
|
1922
|
+
originURL = resolveURL(window.location.href);
|
1923
|
+
|
1924
|
+
/**
|
1925
|
+
* Determine if a URL shares the same origin as the current location
|
1926
|
+
*
|
1927
|
+
* @param {String} requestURL The URL to test
|
1928
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
1929
|
+
*/
|
1930
|
+
return function isURLSameOrigin(requestURL) {
|
1931
|
+
var parsed = utils.isString(requestURL) ? resolveURL(requestURL) : requestURL;
|
1932
|
+
return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
|
1933
|
+
};
|
1934
|
+
}() :
|
1935
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
1936
|
+
function nonStandardBrowserEnv() {
|
1937
|
+
return function isURLSameOrigin() {
|
1938
|
+
return true;
|
1939
|
+
};
|
1940
|
+
}();
|
1941
|
+
|
1942
|
+
function parseProtocol(url) {
|
1943
|
+
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
1944
|
+
return match && match[1] || '';
|
1945
|
+
}
|
1760
1946
|
|
1761
1947
|
/**
|
1762
1948
|
* Calculate data maxRate
|
@@ -1821,7 +2007,8 @@
|
|
1821
2007
|
listener(data);
|
1822
2008
|
};
|
1823
2009
|
}
|
1824
|
-
|
2010
|
+
var isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
2011
|
+
var xhrAdapter = isXHRAdapterSupported && function (config) {
|
1825
2012
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
1826
2013
|
var requestData = config.data;
|
1827
2014
|
var requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
|
@@ -1835,7 +2022,7 @@
|
|
1835
2022
|
config.signal.removeEventListener('abort', onCanceled);
|
1836
2023
|
}
|
1837
2024
|
}
|
1838
|
-
if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
|
2025
|
+
if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
|
1839
2026
|
requestHeaders.setContentType(false); // Let the browser set it
|
1840
2027
|
}
|
1841
2028
|
|
@@ -2000,192 +2187,52 @@
|
|
2000
2187
|
// Send the request
|
2001
2188
|
request.send(requestData || null);
|
2002
2189
|
});
|
2003
|
-
}
|
2004
|
-
|
2005
|
-
var adapters = {
|
2006
|
-
http: xhrAdapter,
|
2007
|
-
xhr: xhrAdapter
|
2008
|
-
};
|
2009
|
-
var adapters$1 = {
|
2010
|
-
getAdapter: function getAdapter(nameOrAdapter) {
|
2011
|
-
if (utils.isString(nameOrAdapter)) {
|
2012
|
-
var adapter = adapters[nameOrAdapter];
|
2013
|
-
if (!nameOrAdapter) {
|
2014
|
-
throw Error(utils.hasOwnProp(nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Can not resolve adapter '".concat(nameOrAdapter, "'"));
|
2015
|
-
}
|
2016
|
-
return adapter;
|
2017
|
-
}
|
2018
|
-
if (!utils.isFunction(nameOrAdapter)) {
|
2019
|
-
throw new TypeError('adapter is not a function');
|
2020
|
-
}
|
2021
|
-
return nameOrAdapter;
|
2022
|
-
},
|
2023
|
-
adapters: adapters
|
2024
2190
|
};
|
2025
2191
|
|
2026
|
-
var
|
2027
|
-
|
2192
|
+
var knownAdapters = {
|
2193
|
+
http: httpAdapter,
|
2194
|
+
xhr: xhrAdapter
|
2028
2195
|
};
|
2029
|
-
|
2030
|
-
|
2031
|
-
* If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
|
2032
|
-
* adapter
|
2033
|
-
*
|
2034
|
-
* @returns {Function}
|
2035
|
-
*/
|
2036
|
-
function getDefaultAdapter() {
|
2037
|
-
var adapter;
|
2038
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
2039
|
-
// For browsers use XHR adapter
|
2040
|
-
adapter = adapters$1.getAdapter('xhr');
|
2041
|
-
} else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
|
2042
|
-
// For node use HTTP adapter
|
2043
|
-
adapter = adapters$1.getAdapter('http');
|
2044
|
-
}
|
2045
|
-
return adapter;
|
2046
|
-
}
|
2047
|
-
|
2048
|
-
/**
|
2049
|
-
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
2050
|
-
* of the input
|
2051
|
-
*
|
2052
|
-
* @param {any} rawValue - The value to be stringified.
|
2053
|
-
* @param {Function} parser - A function that parses a string into a JavaScript object.
|
2054
|
-
* @param {Function} encoder - A function that takes a value and returns a string.
|
2055
|
-
*
|
2056
|
-
* @returns {string} A stringified version of the rawValue.
|
2057
|
-
*/
|
2058
|
-
function stringifySafely(rawValue, parser, encoder) {
|
2059
|
-
if (utils.isString(rawValue)) {
|
2196
|
+
utils.forEach(knownAdapters, function (fn, value) {
|
2197
|
+
if (fn) {
|
2060
2198
|
try {
|
2061
|
-
(
|
2062
|
-
|
2199
|
+
Object.defineProperty(fn, 'name', {
|
2200
|
+
value: value
|
2201
|
+
});
|
2063
2202
|
} catch (e) {
|
2064
|
-
|
2065
|
-
throw e;
|
2066
|
-
}
|
2203
|
+
// eslint-disable-next-line no-empty
|
2067
2204
|
}
|
2205
|
+
Object.defineProperty(fn, 'adapterName', {
|
2206
|
+
value: value
|
2207
|
+
});
|
2068
2208
|
}
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
var
|
2076
|
-
var
|
2077
|
-
var
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
var isFormData = utils.isFormData(data);
|
2082
|
-
if (isFormData) {
|
2083
|
-
if (!hasJSONContentType) {
|
2084
|
-
return data;
|
2209
|
+
});
|
2210
|
+
var adapters = {
|
2211
|
+
getAdapter: function getAdapter(adapters) {
|
2212
|
+
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
2213
|
+
var _adapters = adapters,
|
2214
|
+
length = _adapters.length;
|
2215
|
+
var nameOrAdapter;
|
2216
|
+
var adapter;
|
2217
|
+
for (var i = 0; i < length; i++) {
|
2218
|
+
nameOrAdapter = adapters[i];
|
2219
|
+
if (adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter) {
|
2220
|
+
break;
|
2085
2221
|
}
|
2086
|
-
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
2087
|
-
}
|
2088
|
-
if (utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data)) {
|
2089
|
-
return data;
|
2090
|
-
}
|
2091
|
-
if (utils.isArrayBufferView(data)) {
|
2092
|
-
return data.buffer;
|
2093
|
-
}
|
2094
|
-
if (utils.isURLSearchParams(data)) {
|
2095
|
-
headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
|
2096
|
-
return data.toString();
|
2097
2222
|
}
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
return toURLEncodedForm(data, this.formSerializer).toString();
|
2102
|
-
}
|
2103
|
-
if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
|
2104
|
-
var _FormData = this.env && this.env.FormData;
|
2105
|
-
return toFormData(isFileList ? {
|
2106
|
-
'files[]': data
|
2107
|
-
} : data, _FormData && new _FormData(), this.formSerializer);
|
2223
|
+
if (!adapter) {
|
2224
|
+
if (adapter === false) {
|
2225
|
+
throw new AxiosError("Adapter ".concat(nameOrAdapter, " is not supported by the environment"), 'ERR_NOT_SUPPORT');
|
2108
2226
|
}
|
2227
|
+
throw new Error(utils.hasOwnProp(knownAdapters, nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Unknown adapter '".concat(nameOrAdapter, "'"));
|
2109
2228
|
}
|
2110
|
-
if (
|
2111
|
-
|
2112
|
-
return stringifySafely(data);
|
2113
|
-
}
|
2114
|
-
return data;
|
2115
|
-
}],
|
2116
|
-
transformResponse: [function transformResponse(data) {
|
2117
|
-
var transitional = this.transitional || defaults.transitional;
|
2118
|
-
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
2119
|
-
var JSONRequested = this.responseType === 'json';
|
2120
|
-
if (data && utils.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
|
2121
|
-
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
2122
|
-
var strictJSONParsing = !silentJSONParsing && JSONRequested;
|
2123
|
-
try {
|
2124
|
-
return JSON.parse(data);
|
2125
|
-
} catch (e) {
|
2126
|
-
if (strictJSONParsing) {
|
2127
|
-
if (e.name === 'SyntaxError') {
|
2128
|
-
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
|
2129
|
-
}
|
2130
|
-
throw e;
|
2131
|
-
}
|
2132
|
-
}
|
2229
|
+
if (!utils.isFunction(adapter)) {
|
2230
|
+
throw new TypeError('adapter is not a function');
|
2133
2231
|
}
|
2134
|
-
return
|
2135
|
-
}],
|
2136
|
-
/**
|
2137
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
2138
|
-
* timeout is not created.
|
2139
|
-
*/
|
2140
|
-
timeout: 0,
|
2141
|
-
xsrfCookieName: 'XSRF-TOKEN',
|
2142
|
-
xsrfHeaderName: 'X-XSRF-TOKEN',
|
2143
|
-
maxContentLength: -1,
|
2144
|
-
maxBodyLength: -1,
|
2145
|
-
env: {
|
2146
|
-
FormData: platform.classes.FormData,
|
2147
|
-
Blob: platform.classes.Blob
|
2232
|
+
return adapter;
|
2148
2233
|
},
|
2149
|
-
|
2150
|
-
return status >= 200 && status < 300;
|
2151
|
-
},
|
2152
|
-
headers: {
|
2153
|
-
common: {
|
2154
|
-
'Accept': 'application/json, text/plain, */*'
|
2155
|
-
}
|
2156
|
-
}
|
2234
|
+
adapters: knownAdapters
|
2157
2235
|
};
|
2158
|
-
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
2159
|
-
defaults.headers[method] = {};
|
2160
|
-
});
|
2161
|
-
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
2162
|
-
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
2163
|
-
});
|
2164
|
-
var defaults$1 = defaults;
|
2165
|
-
|
2166
|
-
/**
|
2167
|
-
* Transform the data for a request or a response
|
2168
|
-
*
|
2169
|
-
* @param {Array|Function} fns A single function or Array of functions
|
2170
|
-
* @param {?Object} response The response object
|
2171
|
-
*
|
2172
|
-
* @returns {*} The resulting transformed data
|
2173
|
-
*/
|
2174
|
-
function transformData(fns, response) {
|
2175
|
-
var config = this || defaults$1;
|
2176
|
-
var context = response || config;
|
2177
|
-
var headers = AxiosHeaders$1.from(context.headers);
|
2178
|
-
var data = context.data;
|
2179
|
-
utils.forEach(fns, function transform(fn) {
|
2180
|
-
data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
|
2181
|
-
});
|
2182
|
-
headers.normalize();
|
2183
|
-
return data;
|
2184
|
-
}
|
2185
|
-
|
2186
|
-
function isCancel(value) {
|
2187
|
-
return !!(value && value.__CANCEL__);
|
2188
|
-
}
|
2189
2236
|
|
2190
2237
|
/**
|
2191
2238
|
* Throws a `CanceledError` if cancellation has been requested.
|
@@ -2199,7 +2246,7 @@
|
|
2199
2246
|
config.cancelToken.throwIfRequested();
|
2200
2247
|
}
|
2201
2248
|
if (config.signal && config.signal.aborted) {
|
2202
|
-
throw new CanceledError();
|
2249
|
+
throw new CanceledError(null, config);
|
2203
2250
|
}
|
2204
2251
|
}
|
2205
2252
|
|
@@ -2219,7 +2266,7 @@
|
|
2219
2266
|
if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
|
2220
2267
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
2221
2268
|
}
|
2222
|
-
var adapter = config.adapter || defaults$1.adapter;
|
2269
|
+
var adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
|
2223
2270
|
return adapter(config).then(function onAdapterResolution(response) {
|
2224
2271
|
throwIfCancellationRequested(config);
|
2225
2272
|
|
@@ -2344,7 +2391,7 @@
|
|
2344
2391
|
return config;
|
2345
2392
|
}
|
2346
2393
|
|
2347
|
-
var VERSION = "1.2.
|
2394
|
+
var VERSION = "1.2.1";
|
2348
2395
|
|
2349
2396
|
var validators$1 = {};
|
2350
2397
|
|
@@ -2791,6 +2838,9 @@
|
|
2791
2838
|
|
2792
2839
|
// Expose isAxiosError
|
2793
2840
|
axios.isAxiosError = isAxiosError;
|
2841
|
+
|
2842
|
+
// Expose mergeConfig
|
2843
|
+
axios.mergeConfig = mergeConfig;
|
2794
2844
|
axios.AxiosHeaders = AxiosHeaders$1;
|
2795
2845
|
axios.formToJSON = function (thing) {
|
2796
2846
|
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|