axios 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.1.3 Copyright (c) 2022 Matt Zabriskie and contributors
1
+ // Axios v1.2.0 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) :
@@ -36,6 +36,52 @@
36
36
  });
37
37
  return Constructor;
38
38
  }
39
+ function _slicedToArray(arr, i) {
40
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
41
+ }
42
+ function _arrayWithHoles(arr) {
43
+ if (Array.isArray(arr)) return arr;
44
+ }
45
+ function _iterableToArrayLimit(arr, i) {
46
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
47
+ if (_i == null) return;
48
+ var _arr = [];
49
+ var _n = true;
50
+ var _d = false;
51
+ var _s, _e;
52
+ try {
53
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
54
+ _arr.push(_s.value);
55
+ if (i && _arr.length === i) break;
56
+ }
57
+ } catch (err) {
58
+ _d = true;
59
+ _e = err;
60
+ } finally {
61
+ try {
62
+ if (!_n && _i["return"] != null) _i["return"]();
63
+ } finally {
64
+ if (_d) throw _e;
65
+ }
66
+ }
67
+ return _arr;
68
+ }
69
+ function _unsupportedIterableToArray(o, minLen) {
70
+ if (!o) return;
71
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
72
+ var n = Object.prototype.toString.call(o).slice(8, -1);
73
+ if (n === "Object" && o.constructor) n = o.constructor.name;
74
+ if (n === "Map" || n === "Set") return Array.from(o);
75
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
76
+ }
77
+ function _arrayLikeToArray(arr, len) {
78
+ if (len == null || len > arr.length) len = arr.length;
79
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
80
+ return arr2;
81
+ }
82
+ function _nonIterableRest() {
83
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
84
+ }
39
85
 
40
86
  function bind(fn, thisArg) {
41
87
  return function wrap() {
@@ -274,7 +320,7 @@
274
320
  * @param {Function} fn The callback to invoke for each item
275
321
  *
276
322
  * @param {Boolean} [allOwnKeys = false]
277
- * @returns {void}
323
+ * @returns {any}
278
324
  */
279
325
  function forEach(obj, fn) {
280
326
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
@@ -308,6 +354,23 @@
308
354
  }
309
355
  }
310
356
  }
357
+ function findKey(obj, key) {
358
+ key = key.toLowerCase();
359
+ var keys = Object.keys(obj);
360
+ var i = keys.length;
361
+ var _key;
362
+ while (i-- > 0) {
363
+ _key = keys[i];
364
+ if (key === _key.toLowerCase()) {
365
+ return _key;
366
+ }
367
+ }
368
+ return null;
369
+ }
370
+ var _global = typeof self === "undefined" ? typeof global === "undefined" ? undefined : global : self;
371
+ var isContextDefined = function isContextDefined(context) {
372
+ return !isUndefined(context) && context !== _global;
373
+ };
311
374
 
312
375
  /**
313
376
  * Accepts varargs expecting each argument to be an object, then
@@ -329,16 +392,19 @@
329
392
  */
330
393
  function /* obj1, obj2, obj3, ... */
331
394
  merge() {
395
+ var _ref2 = isContextDefined(this) && this || {},
396
+ caseless = _ref2.caseless;
332
397
  var result = {};
333
398
  var assignValue = function assignValue(val, key) {
334
- if (isPlainObject(result[key]) && isPlainObject(val)) {
335
- result[key] = merge(result[key], val);
399
+ var targetKey = caseless && findKey(result, key) || key;
400
+ if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
401
+ result[targetKey] = merge(result[targetKey], val);
336
402
  } else if (isPlainObject(val)) {
337
- result[key] = merge({}, val);
403
+ result[targetKey] = merge({}, val);
338
404
  } else if (isArray(val)) {
339
- result[key] = val.slice();
405
+ result[targetKey] = val.slice();
340
406
  } else {
341
- result[key] = val;
407
+ result[targetKey] = val;
342
408
  }
343
409
  };
344
410
  for (var i = 0, l = arguments.length; i < l; i++) {
@@ -358,8 +424,8 @@
358
424
  * @returns {Object} The resulting value of object a
359
425
  */
360
426
  var extend = function extend(a, b, thisArg) {
361
- var _ref2 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
362
- allOwnKeys = _ref2.allOwnKeys;
427
+ var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {},
428
+ allOwnKeys = _ref3.allOwnKeys;
363
429
  forEach(b, function (val, key) {
364
430
  if (thisArg && isFunction(val)) {
365
431
  a[key] = bind(val, thisArg);
@@ -534,8 +600,8 @@
534
600
  };
535
601
 
536
602
  /* Creating a function that will check if an object has a property. */
537
- var hasOwnProperty = function (_ref3) {
538
- var hasOwnProperty = _ref3.hasOwnProperty;
603
+ var hasOwnProperty = function (_ref4) {
604
+ var hasOwnProperty = _ref4.hasOwnProperty;
539
605
  return function (obj, prop) {
540
606
  return hasOwnProperty.call(obj, prop);
541
607
  };
@@ -567,6 +633,10 @@
567
633
 
568
634
  var freezeMethods = function freezeMethods(obj) {
569
635
  reduceDescriptors(obj, function (descriptor, name) {
636
+ // skip restricted props in strict mode
637
+ if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
638
+ return false;
639
+ }
570
640
  var value = obj[name];
571
641
  if (!isFunction(value)) return;
572
642
  descriptor.enumerable = false;
@@ -576,7 +646,7 @@
576
646
  }
577
647
  if (!descriptor.set) {
578
648
  descriptor.set = function () {
579
- throw Error('Can not read-only method \'' + name + '\'');
649
+ throw Error('Can not rewrite read-only method \'' + name + '\'');
580
650
  };
581
651
  }
582
652
  });
@@ -596,6 +666,28 @@
596
666
  value = +value;
597
667
  return Number.isFinite(value) ? value : defaultValue;
598
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
+ };
599
691
  var utils = {
600
692
  isArray: isArray,
601
693
  isArrayBuffer: isArrayBuffer,
@@ -639,7 +731,11 @@
639
731
  toObjectSet: toObjectSet,
640
732
  toCamelCase: toCamelCase,
641
733
  noop: noop,
642
- toFiniteNumber: toFiniteNumber
734
+ toFiniteNumber: toFiniteNumber,
735
+ findKey: findKey,
736
+ global: _global,
737
+ isContextDefined: isContextDefined,
738
+ toJSONObject: toJSONObject
643
739
  };
644
740
 
645
741
  /**
@@ -682,7 +778,7 @@
682
778
  columnNumber: this.columnNumber,
683
779
  stack: this.stack,
684
780
  // Axios
685
- config: this.config,
781
+ config: utils.toJSONObject(this.config),
686
782
  code: this.code,
687
783
  status: this.response && this.response.status ? this.response.status : null
688
784
  };
@@ -719,6 +815,7 @@
719
815
 
720
816
  /* eslint-env browser */
721
817
  var browser = (typeof self === "undefined" ? "undefined" : _typeof(self)) == 'object' ? self.FormData : window.FormData;
818
+ var FormData$2 = browser;
722
819
 
723
820
  /**
724
821
  * Determines if the given thing is a array or js object.
@@ -814,7 +911,7 @@
814
911
  }
815
912
 
816
913
  // eslint-disable-next-line no-param-reassign
817
- formData = formData || new (browser || FormData)();
914
+ formData = formData || new (FormData$2 || FormData)();
818
915
 
819
916
  // eslint-disable-next-line no-param-reassign
820
917
  options = utils.toFlatObject(options, {
@@ -1079,6 +1176,7 @@
1079
1176
  }]);
1080
1177
  return InterceptorManager;
1081
1178
  }();
1179
+ var InterceptorManager$1 = InterceptorManager;
1082
1180
 
1083
1181
  var transitionalDefaults = {
1084
1182
  silentJSONParsing: true,
@@ -1214,203 +1312,145 @@
1214
1312
  return null;
1215
1313
  }
1216
1314
 
1315
+ var DEFAULT_CONTENT_TYPE = {
1316
+ 'Content-Type': undefined
1317
+ };
1318
+
1217
1319
  /**
1218
- * Resolve or reject a Promise based on response status.
1320
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1321
+ * of the input
1219
1322
  *
1220
- * @param {Function} resolve A function that resolves the promise.
1221
- * @param {Function} reject A function that rejects the promise.
1222
- * @param {object} response The response.
1323
+ * @param {any} rawValue - The value to be stringified.
1324
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
1325
+ * @param {Function} encoder - A function that takes a value and returns a string.
1223
1326
  *
1224
- * @returns {object} The response.
1327
+ * @returns {string} A stringified version of the rawValue.
1225
1328
  */
1226
- function settle(resolve, reject, response) {
1227
- var validateStatus = response.config.validateStatus;
1228
- if (!response.status || !validateStatus || validateStatus(response.status)) {
1229
- resolve(response);
1230
- } else {
1231
- 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));
1329
+ function stringifySafely(rawValue, parser, encoder) {
1330
+ if (utils.isString(rawValue)) {
1331
+ try {
1332
+ (parser || JSON.parse)(rawValue);
1333
+ return utils.trim(rawValue);
1334
+ } catch (e) {
1335
+ if (e.name !== 'SyntaxError') {
1336
+ throw e;
1337
+ }
1338
+ }
1232
1339
  }
1340
+ return (encoder || JSON.stringify)(rawValue);
1233
1341
  }
1234
-
1235
- var cookies = platform.isStandardBrowserEnv ?
1236
- // Standard browser envs support document.cookie
1237
- function standardBrowserEnv() {
1238
- return {
1239
- write: function write(name, value, expires, path, domain, secure) {
1240
- var cookie = [];
1241
- cookie.push(name + '=' + encodeURIComponent(value));
1242
- if (utils.isNumber(expires)) {
1243
- cookie.push('expires=' + new Date(expires).toGMTString());
1342
+ var defaults = {
1343
+ transitional: transitionalDefaults,
1344
+ adapter: ['xhr', 'http'],
1345
+ transformRequest: [function transformRequest(data, headers) {
1346
+ var contentType = headers.getContentType() || '';
1347
+ var hasJSONContentType = contentType.indexOf('application/json') > -1;
1348
+ var isObjectPayload = utils.isObject(data);
1349
+ if (isObjectPayload && utils.isHTMLForm(data)) {
1350
+ data = new FormData(data);
1351
+ }
1352
+ var isFormData = utils.isFormData(data);
1353
+ if (isFormData) {
1354
+ if (!hasJSONContentType) {
1355
+ return data;
1244
1356
  }
1245
- if (utils.isString(path)) {
1246
- cookie.push('path=' + path);
1357
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1358
+ }
1359
+ if (utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data)) {
1360
+ return data;
1361
+ }
1362
+ if (utils.isArrayBufferView(data)) {
1363
+ return data.buffer;
1364
+ }
1365
+ if (utils.isURLSearchParams(data)) {
1366
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1367
+ return data.toString();
1368
+ }
1369
+ var isFileList;
1370
+ if (isObjectPayload) {
1371
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1372
+ return toURLEncodedForm(data, this.formSerializer).toString();
1247
1373
  }
1248
- if (utils.isString(domain)) {
1249
- cookie.push('domain=' + domain);
1374
+ if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1375
+ var _FormData = this.env && this.env.FormData;
1376
+ return toFormData(isFileList ? {
1377
+ 'files[]': data
1378
+ } : data, _FormData && new _FormData(), this.formSerializer);
1250
1379
  }
1251
- if (secure === true) {
1252
- cookie.push('secure');
1380
+ }
1381
+ if (isObjectPayload || hasJSONContentType) {
1382
+ headers.setContentType('application/json', false);
1383
+ return stringifySafely(data);
1384
+ }
1385
+ return data;
1386
+ }],
1387
+ transformResponse: [function transformResponse(data) {
1388
+ var transitional = this.transitional || defaults.transitional;
1389
+ var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1390
+ var JSONRequested = this.responseType === 'json';
1391
+ if (data && utils.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
1392
+ var silentJSONParsing = transitional && transitional.silentJSONParsing;
1393
+ var strictJSONParsing = !silentJSONParsing && JSONRequested;
1394
+ try {
1395
+ return JSON.parse(data);
1396
+ } catch (e) {
1397
+ if (strictJSONParsing) {
1398
+ if (e.name === 'SyntaxError') {
1399
+ throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
1400
+ }
1401
+ throw e;
1402
+ }
1253
1403
  }
1254
- document.cookie = cookie.join('; ');
1255
- },
1256
- read: function read(name) {
1257
- var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1258
- return match ? decodeURIComponent(match[3]) : null;
1259
- },
1260
- remove: function remove(name) {
1261
- this.write(name, '', Date.now() - 86400000);
1262
1404
  }
1263
- };
1264
- }() :
1265
- // Non standard browser env (web workers, react-native) lack needed support.
1266
- function nonStandardBrowserEnv() {
1267
- return {
1268
- write: function write() {},
1269
- read: function read() {
1270
- return null;
1271
- },
1272
- remove: function remove() {}
1273
- };
1274
- }();
1405
+ return data;
1406
+ }],
1407
+ /**
1408
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
1409
+ * timeout is not created.
1410
+ */
1411
+ timeout: 0,
1412
+ xsrfCookieName: 'XSRF-TOKEN',
1413
+ xsrfHeaderName: 'X-XSRF-TOKEN',
1414
+ maxContentLength: -1,
1415
+ maxBodyLength: -1,
1416
+ env: {
1417
+ FormData: platform.classes.FormData,
1418
+ Blob: platform.classes.Blob
1419
+ },
1420
+ validateStatus: function validateStatus(status) {
1421
+ return status >= 200 && status < 300;
1422
+ },
1423
+ headers: {
1424
+ common: {
1425
+ 'Accept': 'application/json, text/plain, */*'
1426
+ }
1427
+ }
1428
+ };
1429
+ utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1430
+ defaults.headers[method] = {};
1431
+ });
1432
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1433
+ defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1434
+ });
1435
+ var defaults$1 = defaults;
1275
1436
 
1276
- /**
1277
- * Determines whether the specified URL is absolute
1278
- *
1279
- * @param {string} url The URL to test
1280
- *
1281
- * @returns {boolean} True if the specified URL is absolute, otherwise false
1282
- */
1283
- function isAbsoluteURL(url) {
1284
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1285
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1286
- // by any combination of letters, digits, plus, period, or hyphen.
1287
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1288
- }
1437
+ // RawAxiosHeaders whose duplicates are ignored by node
1438
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
1439
+ var ignoreDuplicateOf = utils.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
1289
1440
 
1290
1441
  /**
1291
- * Creates a new URL by combining the specified URLs
1292
- *
1293
- * @param {string} baseURL The base URL
1294
- * @param {string} relativeURL The relative URL
1442
+ * Parse headers into an object
1295
1443
  *
1296
- * @returns {string} The combined URL
1297
- */
1298
- function combineURLs(baseURL, relativeURL) {
1299
- return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
1300
- }
1301
-
1302
- /**
1303
- * Creates a new URL by combining the baseURL with the requestedURL,
1304
- * only when the requestedURL is not already an absolute URL.
1305
- * If the requestURL is absolute, this function returns the requestedURL untouched.
1444
+ * ```
1445
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
1446
+ * Content-Type: application/json
1447
+ * Connection: keep-alive
1448
+ * Transfer-Encoding: chunked
1449
+ * ```
1306
1450
  *
1307
- * @param {string} baseURL The base URL
1308
- * @param {string} requestedURL Absolute or relative URL to combine
1451
+ * @param {String} rawHeaders Headers needing to be parsed
1309
1452
  *
1310
- * @returns {string} The combined full path
1311
- */
1312
- function buildFullPath(baseURL, requestedURL) {
1313
- if (baseURL && !isAbsoluteURL(requestedURL)) {
1314
- return combineURLs(baseURL, requestedURL);
1315
- }
1316
- return requestedURL;
1317
- }
1318
-
1319
- var isURLSameOrigin = platform.isStandardBrowserEnv ?
1320
- // Standard browser envs have full support of the APIs needed to test
1321
- // whether the request URL is of the same origin as current location.
1322
- function standardBrowserEnv() {
1323
- var msie = /(msie|trident)/i.test(navigator.userAgent);
1324
- var urlParsingNode = document.createElement('a');
1325
- var originURL;
1326
-
1327
- /**
1328
- * Parse a URL to discover it's components
1329
- *
1330
- * @param {String} url The URL to be parsed
1331
- * @returns {Object}
1332
- */
1333
- function resolveURL(url) {
1334
- var href = url;
1335
- if (msie) {
1336
- // IE needs attribute set twice to normalize properties
1337
- urlParsingNode.setAttribute('href', href);
1338
- href = urlParsingNode.href;
1339
- }
1340
- urlParsingNode.setAttribute('href', href);
1341
-
1342
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
1343
- return {
1344
- href: urlParsingNode.href,
1345
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
1346
- host: urlParsingNode.host,
1347
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
1348
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
1349
- hostname: urlParsingNode.hostname,
1350
- port: urlParsingNode.port,
1351
- pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
1352
- };
1353
- }
1354
- originURL = resolveURL(window.location.href);
1355
-
1356
- /**
1357
- * Determine if a URL shares the same origin as the current location
1358
- *
1359
- * @param {String} requestURL The URL to test
1360
- * @returns {boolean} True if URL shares the same origin, otherwise false
1361
- */
1362
- return function isURLSameOrigin(requestURL) {
1363
- var parsed = utils.isString(requestURL) ? resolveURL(requestURL) : requestURL;
1364
- return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
1365
- };
1366
- }() :
1367
- // Non standard browser envs (web workers, react-native) lack needed support.
1368
- function nonStandardBrowserEnv() {
1369
- return function isURLSameOrigin() {
1370
- return true;
1371
- };
1372
- }();
1373
-
1374
- /**
1375
- * A `CanceledError` is an object that is thrown when an operation is canceled.
1376
- *
1377
- * @param {string=} message The message.
1378
- * @param {Object=} config The config.
1379
- * @param {Object=} request The request.
1380
- *
1381
- * @returns {CanceledError} The created error.
1382
- */
1383
- function CanceledError(message, config, request) {
1384
- // eslint-disable-next-line no-eq-null,eqeqeq
1385
- AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1386
- this.name = 'CanceledError';
1387
- }
1388
- utils.inherits(CanceledError, AxiosError, {
1389
- __CANCEL__: true
1390
- });
1391
-
1392
- function parseProtocol(url) {
1393
- var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1394
- return match && match[1] || '';
1395
- }
1396
-
1397
- // RawAxiosHeaders whose duplicates are ignored by node
1398
- // c.f. https://nodejs.org/api/http.html#http_message_headers
1399
- var ignoreDuplicateOf = utils.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
1400
-
1401
- /**
1402
- * Parse headers into an object
1403
- *
1404
- * ```
1405
- * Date: Wed, 27 Aug 2014 08:58:49 GMT
1406
- * Content-Type: application/json
1407
- * Connection: keep-alive
1408
- * Transfer-Encoding: chunked
1409
- * ```
1410
- *
1411
- * @param {String} rawHeaders Headers needing to be parsed
1412
- *
1413
- * @returns {Object} Headers parsed into an object
1453
+ * @returns {Object} Headers parsed into an object
1414
1454
  */
1415
1455
  var parseHeaders = (function (rawHeaders) {
1416
1456
  var parsed = {};
@@ -1438,7 +1478,6 @@
1438
1478
  });
1439
1479
 
1440
1480
  var $internals = Symbol('internals');
1441
- var $defaults = Symbol('defaults');
1442
1481
  function normalizeHeader(header) {
1443
1482
  return header && String(header).trim().toLowerCase();
1444
1483
  }
@@ -1457,6 +1496,9 @@
1457
1496
  }
1458
1497
  return tokens;
1459
1498
  }
1499
+ function isValidHeaderName(str) {
1500
+ return /^[-_a-zA-Z]+$/.test(str.trim());
1501
+ }
1460
1502
  function matchHeaderValue(context, value, header, filter) {
1461
1503
  if (utils.isFunction(filter)) {
1462
1504
  return filter.call(this, value, header);
@@ -1485,153 +1527,408 @@
1485
1527
  });
1486
1528
  });
1487
1529
  }
1488
- function findKey(obj, key) {
1489
- key = key.toLowerCase();
1490
- var keys = Object.keys(obj);
1491
- var i = keys.length;
1492
- var _key;
1493
- while (i-- > 0) {
1494
- _key = keys[i];
1495
- if (key === _key.toLowerCase()) {
1496
- return _key;
1530
+ var AxiosHeaders = /*#__PURE__*/function (_Symbol$iterator, _Symbol$toStringTag) {
1531
+ function AxiosHeaders(headers) {
1532
+ _classCallCheck(this, AxiosHeaders);
1533
+ headers && this.set(headers);
1534
+ }
1535
+ _createClass(AxiosHeaders, [{
1536
+ key: "set",
1537
+ value: function set(header, valueOrRewrite, rewrite) {
1538
+ var self = this;
1539
+ function setHeader(_value, _header, _rewrite) {
1540
+ var lHeader = normalizeHeader(_header);
1541
+ if (!lHeader) {
1542
+ throw new Error('header name must be a non-empty string');
1543
+ }
1544
+ var key = utils.findKey(self, lHeader);
1545
+ if (!key || self[key] === undefined || _rewrite === true || _rewrite === undefined && self[key] !== false) {
1546
+ self[key || _header] = normalizeValue(_value);
1547
+ }
1548
+ }
1549
+ var setHeaders = function setHeaders(headers, _rewrite) {
1550
+ return utils.forEach(headers, function (_value, _header) {
1551
+ return setHeader(_value, _header, _rewrite);
1552
+ });
1553
+ };
1554
+ if (utils.isPlainObject(header) || header instanceof this.constructor) {
1555
+ setHeaders(header, valueOrRewrite);
1556
+ } else if (utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1557
+ setHeaders(parseHeaders(header), valueOrRewrite);
1558
+ } else {
1559
+ header != null && setHeader(valueOrRewrite, header, rewrite);
1560
+ }
1561
+ return this;
1562
+ }
1563
+ }, {
1564
+ key: "get",
1565
+ value: function get(header, parser) {
1566
+ header = normalizeHeader(header);
1567
+ if (header) {
1568
+ var key = utils.findKey(this, header);
1569
+ if (key) {
1570
+ var value = this[key];
1571
+ if (!parser) {
1572
+ return value;
1573
+ }
1574
+ if (parser === true) {
1575
+ return parseTokens(value);
1576
+ }
1577
+ if (utils.isFunction(parser)) {
1578
+ return parser.call(this, value, key);
1579
+ }
1580
+ if (utils.isRegExp(parser)) {
1581
+ return parser.exec(value);
1582
+ }
1583
+ throw new TypeError('parser must be boolean|regexp|function');
1584
+ }
1585
+ }
1586
+ }
1587
+ }, {
1588
+ key: "has",
1589
+ value: function has(header, matcher) {
1590
+ header = normalizeHeader(header);
1591
+ if (header) {
1592
+ var key = utils.findKey(this, header);
1593
+ return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1594
+ }
1595
+ return false;
1596
+ }
1597
+ }, {
1598
+ key: "delete",
1599
+ value: function _delete(header, matcher) {
1600
+ var self = this;
1601
+ var deleted = false;
1602
+ function deleteHeader(_header) {
1603
+ _header = normalizeHeader(_header);
1604
+ if (_header) {
1605
+ var key = utils.findKey(self, _header);
1606
+ if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1607
+ delete self[key];
1608
+ deleted = true;
1609
+ }
1610
+ }
1611
+ }
1612
+ if (utils.isArray(header)) {
1613
+ header.forEach(deleteHeader);
1614
+ } else {
1615
+ deleteHeader(header);
1616
+ }
1617
+ return deleted;
1618
+ }
1619
+ }, {
1620
+ key: "clear",
1621
+ value: function clear() {
1622
+ return Object.keys(this).forEach(this["delete"].bind(this));
1623
+ }
1624
+ }, {
1625
+ key: "normalize",
1626
+ value: function normalize(format) {
1627
+ var self = this;
1628
+ var headers = {};
1629
+ utils.forEach(this, function (value, header) {
1630
+ var key = utils.findKey(headers, header);
1631
+ if (key) {
1632
+ self[key] = normalizeValue(value);
1633
+ delete self[header];
1634
+ return;
1635
+ }
1636
+ var normalized = format ? formatHeader(header) : String(header).trim();
1637
+ if (normalized !== header) {
1638
+ delete self[header];
1639
+ }
1640
+ self[normalized] = normalizeValue(value);
1641
+ headers[normalized] = true;
1642
+ });
1643
+ return this;
1644
+ }
1645
+ }, {
1646
+ key: "concat",
1647
+ value: function concat() {
1648
+ var _this$constructor;
1649
+ for (var _len = arguments.length, targets = new Array(_len), _key = 0; _key < _len; _key++) {
1650
+ targets[_key] = arguments[_key];
1651
+ }
1652
+ return (_this$constructor = this.constructor).concat.apply(_this$constructor, [this].concat(targets));
1653
+ }
1654
+ }, {
1655
+ key: "toJSON",
1656
+ value: function toJSON(asStrings) {
1657
+ var obj = Object.create(null);
1658
+ utils.forEach(this, function (value, header) {
1659
+ value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
1660
+ });
1661
+ return obj;
1662
+ }
1663
+ }, {
1664
+ key: _Symbol$iterator,
1665
+ value: function value() {
1666
+ return Object.entries(this.toJSON())[Symbol.iterator]();
1667
+ }
1668
+ }, {
1669
+ key: "toString",
1670
+ value: function toString() {
1671
+ return Object.entries(this.toJSON()).map(function (_ref) {
1672
+ var _ref2 = _slicedToArray(_ref, 2),
1673
+ header = _ref2[0],
1674
+ value = _ref2[1];
1675
+ return header + ': ' + value;
1676
+ }).join('\n');
1677
+ }
1678
+ }, {
1679
+ key: _Symbol$toStringTag,
1680
+ get: function get() {
1681
+ return 'AxiosHeaders';
1682
+ }
1683
+ }], [{
1684
+ key: "from",
1685
+ value: function from(thing) {
1686
+ return thing instanceof this ? thing : new this(thing);
1687
+ }
1688
+ }, {
1689
+ key: "concat",
1690
+ value: function concat(first) {
1691
+ var computed = new this(first);
1692
+ for (var _len2 = arguments.length, targets = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1693
+ targets[_key2 - 1] = arguments[_key2];
1694
+ }
1695
+ targets.forEach(function (target) {
1696
+ return computed.set(target);
1697
+ });
1698
+ return computed;
1699
+ }
1700
+ }, {
1701
+ key: "accessor",
1702
+ value: function accessor(header) {
1703
+ var internals = this[$internals] = this[$internals] = {
1704
+ accessors: {}
1705
+ };
1706
+ var accessors = internals.accessors;
1707
+ var prototype = this.prototype;
1708
+ function defineAccessor(_header) {
1709
+ var lHeader = normalizeHeader(_header);
1710
+ if (!accessors[lHeader]) {
1711
+ buildAccessors(prototype, _header);
1712
+ accessors[lHeader] = true;
1713
+ }
1714
+ }
1715
+ utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1716
+ return this;
1717
+ }
1718
+ }]);
1719
+ return AxiosHeaders;
1720
+ }(Symbol.iterator, Symbol.toStringTag);
1721
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1722
+ utils.freezeMethods(AxiosHeaders.prototype);
1723
+ utils.freezeMethods(AxiosHeaders);
1724
+ var AxiosHeaders$1 = AxiosHeaders;
1725
+
1726
+ /**
1727
+ * Transform the data for a request or a response
1728
+ *
1729
+ * @param {Array|Function} fns A single function or Array of functions
1730
+ * @param {?Object} response The response object
1731
+ *
1732
+ * @returns {*} The resulting transformed data
1733
+ */
1734
+ function transformData(fns, response) {
1735
+ var config = this || defaults$1;
1736
+ var context = response || config;
1737
+ var headers = AxiosHeaders$1.from(context.headers);
1738
+ var data = context.data;
1739
+ utils.forEach(fns, function transform(fn) {
1740
+ data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
1741
+ });
1742
+ headers.normalize();
1743
+ return data;
1744
+ }
1745
+
1746
+ function isCancel(value) {
1747
+ return !!(value && value.__CANCEL__);
1748
+ }
1749
+
1750
+ /**
1751
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
1752
+ *
1753
+ * @param {string=} message The message.
1754
+ * @param {Object=} config The config.
1755
+ * @param {Object=} request The request.
1756
+ *
1757
+ * @returns {CanceledError} The created error.
1758
+ */
1759
+ function CanceledError(message, config, request) {
1760
+ // eslint-disable-next-line no-eq-null,eqeqeq
1761
+ AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1762
+ this.name = 'CanceledError';
1763
+ }
1764
+ utils.inherits(CanceledError, AxiosError, {
1765
+ __CANCEL__: true
1766
+ });
1767
+
1768
+ // eslint-disable-next-line strict
1769
+ var httpAdapter = null;
1770
+
1771
+ /**
1772
+ * Resolve or reject a Promise based on response status.
1773
+ *
1774
+ * @param {Function} resolve A function that resolves the promise.
1775
+ * @param {Function} reject A function that rejects the promise.
1776
+ * @param {object} response The response.
1777
+ *
1778
+ * @returns {object} The response.
1779
+ */
1780
+ function settle(resolve, reject, response) {
1781
+ var validateStatus = response.config.validateStatus;
1782
+ if (!response.status || !validateStatus || validateStatus(response.status)) {
1783
+ resolve(response);
1784
+ } else {
1785
+ 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));
1786
+ }
1787
+ }
1788
+
1789
+ var cookies = platform.isStandardBrowserEnv ?
1790
+ // Standard browser envs support document.cookie
1791
+ function standardBrowserEnv() {
1792
+ return {
1793
+ write: function write(name, value, expires, path, domain, secure) {
1794
+ var cookie = [];
1795
+ cookie.push(name + '=' + encodeURIComponent(value));
1796
+ if (utils.isNumber(expires)) {
1797
+ cookie.push('expires=' + new Date(expires).toGMTString());
1798
+ }
1799
+ if (utils.isString(path)) {
1800
+ cookie.push('path=' + path);
1801
+ }
1802
+ if (utils.isString(domain)) {
1803
+ cookie.push('domain=' + domain);
1804
+ }
1805
+ if (secure === true) {
1806
+ cookie.push('secure');
1807
+ }
1808
+ document.cookie = cookie.join('; ');
1809
+ },
1810
+ read: function read(name) {
1811
+ var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1812
+ return match ? decodeURIComponent(match[3]) : null;
1813
+ },
1814
+ remove: function remove(name) {
1815
+ this.write(name, '', Date.now() - 86400000);
1497
1816
  }
1817
+ };
1818
+ }() :
1819
+ // Non standard browser env (web workers, react-native) lack needed support.
1820
+ function nonStandardBrowserEnv() {
1821
+ return {
1822
+ write: function write() {},
1823
+ read: function read() {
1824
+ return null;
1825
+ },
1826
+ remove: function remove() {}
1827
+ };
1828
+ }();
1829
+
1830
+ /**
1831
+ * Determines whether the specified URL is absolute
1832
+ *
1833
+ * @param {string} url The URL to test
1834
+ *
1835
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
1836
+ */
1837
+ function isAbsoluteURL(url) {
1838
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1839
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1840
+ // by any combination of letters, digits, plus, period, or hyphen.
1841
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1842
+ }
1843
+
1844
+ /**
1845
+ * Creates a new URL by combining the specified URLs
1846
+ *
1847
+ * @param {string} baseURL The base URL
1848
+ * @param {string} relativeURL The relative URL
1849
+ *
1850
+ * @returns {string} The combined URL
1851
+ */
1852
+ function combineURLs(baseURL, relativeURL) {
1853
+ return relativeURL ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '') : baseURL;
1854
+ }
1855
+
1856
+ /**
1857
+ * Creates a new URL by combining the baseURL with the requestedURL,
1858
+ * only when the requestedURL is not already an absolute URL.
1859
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
1860
+ *
1861
+ * @param {string} baseURL The base URL
1862
+ * @param {string} requestedURL Absolute or relative URL to combine
1863
+ *
1864
+ * @returns {string} The combined full path
1865
+ */
1866
+ function buildFullPath(baseURL, requestedURL) {
1867
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
1868
+ return combineURLs(baseURL, requestedURL);
1498
1869
  }
1499
- return null;
1500
- }
1501
- function AxiosHeaders(headers, defaults) {
1502
- headers && this.set(headers);
1503
- this[$defaults] = defaults || null;
1870
+ return requestedURL;
1504
1871
  }
1505
- Object.assign(AxiosHeaders.prototype, {
1506
- set: function set(header, valueOrRewrite, rewrite) {
1507
- var self = this;
1508
- function setHeader(_value, _header, _rewrite) {
1509
- var lHeader = normalizeHeader(_header);
1510
- if (!lHeader) {
1511
- throw new Error('header name must be a non-empty string');
1512
- }
1513
- var key = findKey(self, lHeader);
1514
- if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
1515
- return;
1516
- }
1517
- self[key || _header] = normalizeValue(_value);
1518
- }
1519
- if (utils.isPlainObject(header)) {
1520
- utils.forEach(header, function (_value, _header) {
1521
- setHeader(_value, _header, valueOrRewrite);
1522
- });
1523
- } else {
1524
- setHeader(valueOrRewrite, header, rewrite);
1525
- }
1526
- return this;
1527
- },
1528
- get: function get(header, parser) {
1529
- header = normalizeHeader(header);
1530
- if (!header) return undefined;
1531
- var key = findKey(this, header);
1532
- if (key) {
1533
- var value = this[key];
1534
- if (!parser) {
1535
- return value;
1536
- }
1537
- if (parser === true) {
1538
- return parseTokens(value);
1539
- }
1540
- if (utils.isFunction(parser)) {
1541
- return parser.call(this, value, key);
1542
- }
1543
- if (utils.isRegExp(parser)) {
1544
- return parser.exec(value);
1545
- }
1546
- throw new TypeError('parser must be boolean|regexp|function');
1547
- }
1548
- },
1549
- has: function has(header, matcher) {
1550
- header = normalizeHeader(header);
1551
- if (header) {
1552
- var key = findKey(this, header);
1553
- return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1554
- }
1555
- return false;
1556
- },
1557
- "delete": function _delete(header, matcher) {
1558
- var self = this;
1559
- var deleted = false;
1560
- function deleteHeader(_header) {
1561
- _header = normalizeHeader(_header);
1562
- if (_header) {
1563
- var key = findKey(self, _header);
1564
- if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1565
- delete self[key];
1566
- deleted = true;
1567
- }
1568
- }
1569
- }
1570
- if (utils.isArray(header)) {
1571
- header.forEach(deleteHeader);
1572
- } else {
1573
- deleteHeader(header);
1574
- }
1575
- return deleted;
1576
- },
1577
- clear: function clear() {
1578
- return Object.keys(this).forEach(this["delete"].bind(this));
1579
- },
1580
- normalize: function normalize(format) {
1581
- var self = this;
1582
- var headers = {};
1583
- utils.forEach(this, function (value, header) {
1584
- var key = findKey(headers, header);
1585
- if (key) {
1586
- self[key] = normalizeValue(value);
1587
- delete self[header];
1588
- return;
1589
- }
1590
- var normalized = format ? formatHeader(header) : String(header).trim();
1591
- if (normalized !== header) {
1592
- delete self[header];
1593
- }
1594
- self[normalized] = normalizeValue(value);
1595
- headers[normalized] = true;
1596
- });
1597
- return this;
1598
- },
1599
- toJSON: function toJSON(asStrings) {
1600
- var obj = Object.create(null);
1601
- utils.forEach(Object.assign({}, this[$defaults] || null, this), function (value, header) {
1602
- if (value == null || value === false) return;
1603
- obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
1604
- });
1605
- return obj;
1606
- }
1607
- });
1608
- Object.assign(AxiosHeaders, {
1609
- from: function from(thing) {
1610
- if (utils.isString(thing)) {
1611
- return new this(parseHeaders(thing));
1872
+
1873
+ var isURLSameOrigin = platform.isStandardBrowserEnv ?
1874
+ // Standard browser envs have full support of the APIs needed to test
1875
+ // whether the request URL is of the same origin as current location.
1876
+ function standardBrowserEnv() {
1877
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
1878
+ var urlParsingNode = document.createElement('a');
1879
+ var originURL;
1880
+
1881
+ /**
1882
+ * Parse a URL to discover it's components
1883
+ *
1884
+ * @param {String} url The URL to be parsed
1885
+ * @returns {Object}
1886
+ */
1887
+ function resolveURL(url) {
1888
+ var href = url;
1889
+ if (msie) {
1890
+ // IE needs attribute set twice to normalize properties
1891
+ urlParsingNode.setAttribute('href', href);
1892
+ href = urlParsingNode.href;
1612
1893
  }
1613
- return thing instanceof this ? thing : new this(thing);
1614
- },
1615
- accessor: function accessor(header) {
1616
- var internals = this[$internals] = this[$internals] = {
1617
- accessors: {}
1894
+ urlParsingNode.setAttribute('href', href);
1895
+
1896
+ // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
1897
+ return {
1898
+ href: urlParsingNode.href,
1899
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
1900
+ host: urlParsingNode.host,
1901
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
1902
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
1903
+ hostname: urlParsingNode.hostname,
1904
+ port: urlParsingNode.port,
1905
+ pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
1618
1906
  };
1619
- var accessors = internals.accessors;
1620
- var prototype = this.prototype;
1621
- function defineAccessor(_header) {
1622
- var lHeader = normalizeHeader(_header);
1623
- if (!accessors[lHeader]) {
1624
- buildAccessors(prototype, _header);
1625
- accessors[lHeader] = true;
1626
- }
1627
- }
1628
- utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1629
- return this;
1630
1907
  }
1631
- });
1632
- AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1633
- utils.freezeMethods(AxiosHeaders.prototype);
1634
- utils.freezeMethods(AxiosHeaders);
1908
+ originURL = resolveURL(window.location.href);
1909
+
1910
+ /**
1911
+ * Determine if a URL shares the same origin as the current location
1912
+ *
1913
+ * @param {String} requestURL The URL to test
1914
+ * @returns {boolean} True if URL shares the same origin, otherwise false
1915
+ */
1916
+ return function isURLSameOrigin(requestURL) {
1917
+ var parsed = utils.isString(requestURL) ? resolveURL(requestURL) : requestURL;
1918
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
1919
+ };
1920
+ }() :
1921
+ // Non standard browser envs (web workers, react-native) lack needed support.
1922
+ function nonStandardBrowserEnv() {
1923
+ return function isURLSameOrigin() {
1924
+ return true;
1925
+ };
1926
+ }();
1927
+
1928
+ function parseProtocol(url) {
1929
+ var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1930
+ return match && match[1] || '';
1931
+ }
1635
1932
 
1636
1933
  /**
1637
1934
  * Calculate data maxRate
@@ -1689,16 +1986,18 @@
1689
1986
  progress: total ? loaded / total : undefined,
1690
1987
  bytes: progressBytes,
1691
1988
  rate: rate ? rate : undefined,
1692
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined
1989
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
1990
+ event: e
1693
1991
  };
1694
1992
  data[isDownloadStream ? 'download' : 'upload'] = true;
1695
1993
  listener(data);
1696
1994
  };
1697
1995
  }
1698
- function xhrAdapter(config) {
1996
+ var isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
1997
+ var xhrAdapter = isXHRAdapterSupported && function (config) {
1699
1998
  return new Promise(function dispatchXhrRequest(resolve, reject) {
1700
1999
  var requestData = config.data;
1701
- var requestHeaders = AxiosHeaders.from(config.headers).normalize();
2000
+ var requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
1702
2001
  var responseType = config.responseType;
1703
2002
  var onCanceled;
1704
2003
  function done() {
@@ -1731,7 +2030,7 @@
1731
2030
  return;
1732
2031
  }
1733
2032
  // Prepare the response
1734
- var responseHeaders = AxiosHeaders.from('getAllResponseHeaders' in request && request.getAllResponseHeaders());
2033
+ var responseHeaders = AxiosHeaders$1.from('getAllResponseHeaders' in request && request.getAllResponseHeaders());
1735
2034
  var responseData = !responseType || responseType === 'text' || responseType === 'json' ? request.responseText : request.response;
1736
2035
  var response = {
1737
2036
  data: responseData,
@@ -1874,191 +2173,52 @@
1874
2173
  // Send the request
1875
2174
  request.send(requestData || null);
1876
2175
  });
1877
- }
1878
-
1879
- var adapters = {
1880
- http: xhrAdapter,
1881
- xhr: xhrAdapter
1882
- };
1883
- var adapters$1 = {
1884
- getAdapter: function getAdapter(nameOrAdapter) {
1885
- if (utils.isString(nameOrAdapter)) {
1886
- var adapter = adapters[nameOrAdapter];
1887
- if (!nameOrAdapter) {
1888
- throw Error(utils.hasOwnProp(nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Can not resolve adapter '".concat(nameOrAdapter, "'"));
1889
- }
1890
- return adapter;
1891
- }
1892
- if (!utils.isFunction(nameOrAdapter)) {
1893
- throw new TypeError('adapter is not a function');
1894
- }
1895
- return nameOrAdapter;
1896
- },
1897
- adapters: adapters
1898
2176
  };
1899
2177
 
1900
- var DEFAULT_CONTENT_TYPE = {
1901
- 'Content-Type': 'application/x-www-form-urlencoded'
2178
+ var knownAdapters = {
2179
+ http: httpAdapter,
2180
+ xhr: xhrAdapter
1902
2181
  };
1903
-
1904
- /**
1905
- * If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
1906
- * adapter
1907
- *
1908
- * @returns {Function}
1909
- */
1910
- function getDefaultAdapter() {
1911
- var adapter;
1912
- if (typeof XMLHttpRequest !== 'undefined') {
1913
- // For browsers use XHR adapter
1914
- adapter = adapters$1.getAdapter('xhr');
1915
- } else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
1916
- // For node use HTTP adapter
1917
- adapter = adapters$1.getAdapter('http');
1918
- }
1919
- return adapter;
1920
- }
1921
-
1922
- /**
1923
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1924
- * of the input
1925
- *
1926
- * @param {any} rawValue - The value to be stringified.
1927
- * @param {Function} parser - A function that parses a string into a JavaScript object.
1928
- * @param {Function} encoder - A function that takes a value and returns a string.
1929
- *
1930
- * @returns {string} A stringified version of the rawValue.
1931
- */
1932
- function stringifySafely(rawValue, parser, encoder) {
1933
- if (utils.isString(rawValue)) {
2182
+ utils.forEach(knownAdapters, function (fn, value) {
2183
+ if (fn) {
1934
2184
  try {
1935
- (parser || JSON.parse)(rawValue);
1936
- return utils.trim(rawValue);
2185
+ Object.defineProperty(fn, 'name', {
2186
+ value: value
2187
+ });
1937
2188
  } catch (e) {
1938
- if (e.name !== 'SyntaxError') {
1939
- throw e;
1940
- }
2189
+ // eslint-disable-next-line no-empty
1941
2190
  }
2191
+ Object.defineProperty(fn, 'adapterName', {
2192
+ value: value
2193
+ });
1942
2194
  }
1943
- return (encoder || JSON.stringify)(rawValue);
1944
- }
1945
- var defaults = {
1946
- transitional: transitionalDefaults,
1947
- adapter: getDefaultAdapter(),
1948
- transformRequest: [function transformRequest(data, headers) {
1949
- var contentType = headers.getContentType() || '';
1950
- var hasJSONContentType = contentType.indexOf('application/json') > -1;
1951
- var isObjectPayload = utils.isObject(data);
1952
- if (isObjectPayload && utils.isHTMLForm(data)) {
1953
- data = new FormData(data);
1954
- }
1955
- var isFormData = utils.isFormData(data);
1956
- if (isFormData) {
1957
- if (!hasJSONContentType) {
1958
- return data;
2195
+ });
2196
+ var adapters = {
2197
+ getAdapter: function getAdapter(adapters) {
2198
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
2199
+ var _adapters = adapters,
2200
+ length = _adapters.length;
2201
+ var nameOrAdapter;
2202
+ var adapter;
2203
+ for (var i = 0; i < length; i++) {
2204
+ nameOrAdapter = adapters[i];
2205
+ if (adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter) {
2206
+ break;
1959
2207
  }
1960
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1961
- }
1962
- if (utils.isArrayBuffer(data) || utils.isBuffer(data) || utils.isStream(data) || utils.isFile(data) || utils.isBlob(data)) {
1963
- return data;
1964
- }
1965
- if (utils.isArrayBufferView(data)) {
1966
- return data.buffer;
1967
- }
1968
- if (utils.isURLSearchParams(data)) {
1969
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1970
- return data.toString();
1971
2208
  }
1972
- var isFileList;
1973
- if (isObjectPayload) {
1974
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1975
- return toURLEncodedForm(data, this.formSerializer).toString();
1976
- }
1977
- if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1978
- var _FormData = this.env && this.env.FormData;
1979
- return toFormData(isFileList ? {
1980
- 'files[]': data
1981
- } : data, _FormData && new _FormData(), this.formSerializer);
2209
+ if (!adapter) {
2210
+ if (adapter === false) {
2211
+ throw new AxiosError("Adapter ".concat(nameOrAdapter, " is not supported by the environment"), 'ERR_NOT_SUPPORT');
1982
2212
  }
2213
+ throw new Error(utils.hasOwnProp(knownAdapters, nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Unknown adapter '".concat(nameOrAdapter, "'"));
1983
2214
  }
1984
- if (isObjectPayload || hasJSONContentType) {
1985
- headers.setContentType('application/json', false);
1986
- return stringifySafely(data);
1987
- }
1988
- return data;
1989
- }],
1990
- transformResponse: [function transformResponse(data) {
1991
- var transitional = this.transitional || defaults.transitional;
1992
- var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1993
- var JSONRequested = this.responseType === 'json';
1994
- if (data && utils.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
1995
- var silentJSONParsing = transitional && transitional.silentJSONParsing;
1996
- var strictJSONParsing = !silentJSONParsing && JSONRequested;
1997
- try {
1998
- return JSON.parse(data);
1999
- } catch (e) {
2000
- if (strictJSONParsing) {
2001
- if (e.name === 'SyntaxError') {
2002
- throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
2003
- }
2004
- throw e;
2005
- }
2006
- }
2215
+ if (!utils.isFunction(adapter)) {
2216
+ throw new TypeError('adapter is not a function');
2007
2217
  }
2008
- return data;
2009
- }],
2010
- /**
2011
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
2012
- * timeout is not created.
2013
- */
2014
- timeout: 0,
2015
- xsrfCookieName: 'XSRF-TOKEN',
2016
- xsrfHeaderName: 'X-XSRF-TOKEN',
2017
- maxContentLength: -1,
2018
- maxBodyLength: -1,
2019
- env: {
2020
- FormData: platform.classes.FormData,
2021
- Blob: platform.classes.Blob
2218
+ return adapter;
2022
2219
  },
2023
- validateStatus: function validateStatus(status) {
2024
- return status >= 200 && status < 300;
2025
- },
2026
- headers: {
2027
- common: {
2028
- 'Accept': 'application/json, text/plain, */*'
2029
- }
2030
- }
2220
+ adapters: knownAdapters
2031
2221
  };
2032
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
2033
- defaults.headers[method] = {};
2034
- });
2035
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
2036
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
2037
- });
2038
-
2039
- /**
2040
- * Transform the data for a request or a response
2041
- *
2042
- * @param {Array|Function} fns A single function or Array of functions
2043
- * @param {?Object} response The response object
2044
- *
2045
- * @returns {*} The resulting transformed data
2046
- */
2047
- function transformData(fns, response) {
2048
- var config = this || defaults;
2049
- var context = response || config;
2050
- var headers = AxiosHeaders.from(context.headers);
2051
- var data = context.data;
2052
- utils.forEach(fns, function transform(fn) {
2053
- data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
2054
- });
2055
- headers.normalize();
2056
- return data;
2057
- }
2058
-
2059
- function isCancel(value) {
2060
- return !!(value && value.__CANCEL__);
2061
- }
2062
2222
 
2063
2223
  /**
2064
2224
  * Throws a `CanceledError` if cancellation has been requested.
@@ -2085,17 +2245,20 @@
2085
2245
  */
2086
2246
  function dispatchRequest(config) {
2087
2247
  throwIfCancellationRequested(config);
2088
- config.headers = AxiosHeaders.from(config.headers);
2248
+ config.headers = AxiosHeaders$1.from(config.headers);
2089
2249
 
2090
2250
  // Transform request data
2091
2251
  config.data = transformData.call(config, config.transformRequest);
2092
- var adapter = config.adapter || defaults.adapter;
2252
+ if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
2253
+ config.headers.setContentType('application/x-www-form-urlencoded', false);
2254
+ }
2255
+ var adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
2093
2256
  return adapter(config).then(function onAdapterResolution(response) {
2094
2257
  throwIfCancellationRequested(config);
2095
2258
 
2096
2259
  // Transform response data
2097
2260
  response.data = transformData.call(config, config.transformResponse, response);
2098
- response.headers = AxiosHeaders.from(response.headers);
2261
+ response.headers = AxiosHeaders$1.from(response.headers);
2099
2262
  return response;
2100
2263
  }, function onAdapterRejection(reason) {
2101
2264
  if (!isCancel(reason)) {
@@ -2104,13 +2267,17 @@
2104
2267
  // Transform response data
2105
2268
  if (reason && reason.response) {
2106
2269
  reason.response.data = transformData.call(config, config.transformResponse, reason.response);
2107
- reason.response.headers = AxiosHeaders.from(reason.response.headers);
2270
+ reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
2108
2271
  }
2109
2272
  }
2110
2273
  return Promise.reject(reason);
2111
2274
  });
2112
2275
  }
2113
2276
 
2277
+ var headersToObject = function headersToObject(thing) {
2278
+ return thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
2279
+ };
2280
+
2114
2281
  /**
2115
2282
  * Config-specific merge-function which creates a new config-object
2116
2283
  * by merging two configuration objects together.
@@ -2124,9 +2291,11 @@
2124
2291
  // eslint-disable-next-line no-param-reassign
2125
2292
  config2 = config2 || {};
2126
2293
  var config = {};
2127
- function getMergedValue(target, source) {
2294
+ function getMergedValue(target, source, caseless) {
2128
2295
  if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
2129
- return utils.merge(target, source);
2296
+ return utils.merge.call({
2297
+ caseless: caseless
2298
+ }, target, source);
2130
2299
  } else if (utils.isPlainObject(source)) {
2131
2300
  return utils.merge({}, source);
2132
2301
  } else if (utils.isArray(source)) {
@@ -2136,76 +2305,79 @@
2136
2305
  }
2137
2306
 
2138
2307
  // eslint-disable-next-line consistent-return
2139
- function mergeDeepProperties(prop) {
2140
- if (!utils.isUndefined(config2[prop])) {
2141
- return getMergedValue(config1[prop], config2[prop]);
2142
- } else if (!utils.isUndefined(config1[prop])) {
2143
- return getMergedValue(undefined, config1[prop]);
2308
+ function mergeDeepProperties(a, b, caseless) {
2309
+ if (!utils.isUndefined(b)) {
2310
+ return getMergedValue(a, b, caseless);
2311
+ } else if (!utils.isUndefined(a)) {
2312
+ return getMergedValue(undefined, a, caseless);
2144
2313
  }
2145
2314
  }
2146
2315
 
2147
2316
  // eslint-disable-next-line consistent-return
2148
- function valueFromConfig2(prop) {
2149
- if (!utils.isUndefined(config2[prop])) {
2150
- return getMergedValue(undefined, config2[prop]);
2317
+ function valueFromConfig2(a, b) {
2318
+ if (!utils.isUndefined(b)) {
2319
+ return getMergedValue(undefined, b);
2151
2320
  }
2152
2321
  }
2153
2322
 
2154
2323
  // eslint-disable-next-line consistent-return
2155
- function defaultToConfig2(prop) {
2156
- if (!utils.isUndefined(config2[prop])) {
2157
- return getMergedValue(undefined, config2[prop]);
2158
- } else if (!utils.isUndefined(config1[prop])) {
2159
- return getMergedValue(undefined, config1[prop]);
2324
+ function defaultToConfig2(a, b) {
2325
+ if (!utils.isUndefined(b)) {
2326
+ return getMergedValue(undefined, b);
2327
+ } else if (!utils.isUndefined(a)) {
2328
+ return getMergedValue(undefined, a);
2160
2329
  }
2161
2330
  }
2162
2331
 
2163
2332
  // eslint-disable-next-line consistent-return
2164
- function mergeDirectKeys(prop) {
2333
+ function mergeDirectKeys(a, b, prop) {
2165
2334
  if (prop in config2) {
2166
- return getMergedValue(config1[prop], config2[prop]);
2335
+ return getMergedValue(a, b);
2167
2336
  } else if (prop in config1) {
2168
- return getMergedValue(undefined, config1[prop]);
2337
+ return getMergedValue(undefined, a);
2169
2338
  }
2170
2339
  }
2171
2340
  var mergeMap = {
2172
- 'url': valueFromConfig2,
2173
- 'method': valueFromConfig2,
2174
- 'data': valueFromConfig2,
2175
- 'baseURL': defaultToConfig2,
2176
- 'transformRequest': defaultToConfig2,
2177
- 'transformResponse': defaultToConfig2,
2178
- 'paramsSerializer': defaultToConfig2,
2179
- 'timeout': defaultToConfig2,
2180
- 'timeoutMessage': defaultToConfig2,
2181
- 'withCredentials': defaultToConfig2,
2182
- 'adapter': defaultToConfig2,
2183
- 'responseType': defaultToConfig2,
2184
- 'xsrfCookieName': defaultToConfig2,
2185
- 'xsrfHeaderName': defaultToConfig2,
2186
- 'onUploadProgress': defaultToConfig2,
2187
- 'onDownloadProgress': defaultToConfig2,
2188
- 'decompress': defaultToConfig2,
2189
- 'maxContentLength': defaultToConfig2,
2190
- 'maxBodyLength': defaultToConfig2,
2191
- 'beforeRedirect': defaultToConfig2,
2192
- 'transport': defaultToConfig2,
2193
- 'httpAgent': defaultToConfig2,
2194
- 'httpsAgent': defaultToConfig2,
2195
- 'cancelToken': defaultToConfig2,
2196
- 'socketPath': defaultToConfig2,
2197
- 'responseEncoding': defaultToConfig2,
2198
- 'validateStatus': mergeDirectKeys
2341
+ url: valueFromConfig2,
2342
+ method: valueFromConfig2,
2343
+ data: valueFromConfig2,
2344
+ baseURL: defaultToConfig2,
2345
+ transformRequest: defaultToConfig2,
2346
+ transformResponse: defaultToConfig2,
2347
+ paramsSerializer: defaultToConfig2,
2348
+ timeout: defaultToConfig2,
2349
+ timeoutMessage: defaultToConfig2,
2350
+ withCredentials: defaultToConfig2,
2351
+ adapter: defaultToConfig2,
2352
+ responseType: defaultToConfig2,
2353
+ xsrfCookieName: defaultToConfig2,
2354
+ xsrfHeaderName: defaultToConfig2,
2355
+ onUploadProgress: defaultToConfig2,
2356
+ onDownloadProgress: defaultToConfig2,
2357
+ decompress: defaultToConfig2,
2358
+ maxContentLength: defaultToConfig2,
2359
+ maxBodyLength: defaultToConfig2,
2360
+ beforeRedirect: defaultToConfig2,
2361
+ transport: defaultToConfig2,
2362
+ httpAgent: defaultToConfig2,
2363
+ httpsAgent: defaultToConfig2,
2364
+ cancelToken: defaultToConfig2,
2365
+ socketPath: defaultToConfig2,
2366
+ responseEncoding: defaultToConfig2,
2367
+ validateStatus: mergeDirectKeys,
2368
+ headers: function headers(a, b) {
2369
+ return mergeDeepProperties(headersToObject(a), headersToObject(b), true);
2370
+ }
2199
2371
  };
2200
2372
  utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
2201
2373
  var merge = mergeMap[prop] || mergeDeepProperties;
2202
- var configValue = merge(prop);
2374
+ var configValue = merge(config1[prop], config2[prop], prop);
2203
2375
  utils.isUndefined(configValue) && merge !== mergeDirectKeys || (config[prop] = configValue);
2204
2376
  });
2205
2377
  return config;
2206
2378
  }
2207
2379
 
2208
- var VERSION = "1.1.3";
2380
+ var VERSION = "1.2.0";
2209
2381
 
2210
2382
  var validators$1 = {};
2211
2383
 
@@ -2296,8 +2468,8 @@
2296
2468
  _classCallCheck(this, Axios);
2297
2469
  this.defaults = instanceConfig;
2298
2470
  this.interceptors = {
2299
- request: new InterceptorManager(),
2300
- response: new InterceptorManager()
2471
+ request: new InterceptorManager$1(),
2472
+ response: new InterceptorManager$1()
2301
2473
  };
2302
2474
  }
2303
2475
 
@@ -2323,7 +2495,8 @@
2323
2495
  config = mergeConfig(this.defaults, config);
2324
2496
  var _config = config,
2325
2497
  transitional = _config.transitional,
2326
- paramsSerializer = _config.paramsSerializer;
2498
+ paramsSerializer = _config.paramsSerializer,
2499
+ headers = _config.headers;
2327
2500
  if (transitional !== undefined) {
2328
2501
  validator.assertOptions(transitional, {
2329
2502
  silentJSONParsing: validators.transitional(validators["boolean"]),
@@ -2340,13 +2513,14 @@
2340
2513
 
2341
2514
  // Set config.method
2342
2515
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2516
+ var contextHeaders;
2343
2517
 
2344
2518
  // Flatten headers
2345
- var defaultHeaders = config.headers && utils.merge(config.headers.common, config.headers[config.method]);
2346
- defaultHeaders && utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], function cleanHeaderConfig(method) {
2347
- delete config.headers[method];
2519
+ contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
2520
+ contextHeaders && utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], function (method) {
2521
+ delete headers[method];
2348
2522
  });
2349
- config.headers = new AxiosHeaders(config.headers, defaultHeaders);
2523
+ config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
2350
2524
 
2351
2525
  // filter out skipped interceptors
2352
2526
  var requestInterceptorChain = [];
@@ -2439,6 +2613,7 @@
2439
2613
  Axios.prototype[method] = generateHTTPMethod();
2440
2614
  Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
2441
2615
  });
2616
+ var Axios$1 = Axios;
2442
2617
 
2443
2618
  /**
2444
2619
  * A `CancelToken` is an object that can be used to request cancellation of an operation.
@@ -2554,6 +2729,7 @@
2554
2729
  }]);
2555
2730
  return CancelToken;
2556
2731
  }();
2732
+ var CancelToken$1 = CancelToken;
2557
2733
 
2558
2734
  /**
2559
2735
  * Syntactic sugar for invoking a function and expanding an array for arguments.
@@ -2601,11 +2777,11 @@
2601
2777
  * @returns {Axios} A new instance of Axios
2602
2778
  */
2603
2779
  function createInstance(defaultConfig) {
2604
- var context = new Axios(defaultConfig);
2605
- var instance = bind(Axios.prototype.request, context);
2780
+ var context = new Axios$1(defaultConfig);
2781
+ var instance = bind(Axios$1.prototype.request, context);
2606
2782
 
2607
2783
  // Copy axios.prototype to instance
2608
- utils.extend(instance, Axios.prototype, context, {
2784
+ utils.extend(instance, Axios$1.prototype, context, {
2609
2785
  allOwnKeys: true
2610
2786
  });
2611
2787
 
@@ -2622,14 +2798,14 @@
2622
2798
  }
2623
2799
 
2624
2800
  // Create the default instance to be exported
2625
- var axios = createInstance(defaults);
2801
+ var axios = createInstance(defaults$1);
2626
2802
 
2627
2803
  // Expose Axios class to allow class inheritance
2628
- axios.Axios = Axios;
2804
+ axios.Axios = Axios$1;
2629
2805
 
2630
2806
  // Expose Cancel & CancelToken
2631
2807
  axios.CanceledError = CanceledError;
2632
- axios.CancelToken = CancelToken;
2808
+ axios.CancelToken = CancelToken$1;
2633
2809
  axios.isCancel = isCancel;
2634
2810
  axios.VERSION = VERSION;
2635
2811
  axios.toFormData = toFormData;
@@ -2648,9 +2824,11 @@
2648
2824
 
2649
2825
  // Expose isAxiosError
2650
2826
  axios.isAxiosError = isAxiosError;
2827
+ axios.AxiosHeaders = AxiosHeaders$1;
2651
2828
  axios.formToJSON = function (thing) {
2652
2829
  return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
2653
2830
  };
2831
+ axios["default"] = axios;
2654
2832
 
2655
2833
  return axios;
2656
2834