axios 1.1.3 → 1.3.3

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.

Files changed (47) hide show
  1. package/CHANGELOG.md +298 -75
  2. package/{UPGRADE_GUIDE.md → MIGRATION_GUIDE.md} +1 -1
  3. package/README.md +61 -25
  4. package/dist/axios.js +886 -582
  5. package/dist/axios.js.map +1 -1
  6. package/dist/axios.min.js +1 -1
  7. package/dist/axios.min.js.map +1 -1
  8. package/dist/browser/axios.cjs +3189 -0
  9. package/dist/browser/axios.cjs.map +1 -0
  10. package/dist/esm/axios.js +886 -625
  11. package/dist/esm/axios.js.map +1 -1
  12. package/dist/esm/axios.min.js +1 -1
  13. package/dist/esm/axios.min.js.map +1 -1
  14. package/dist/node/axios.cjs +972 -554
  15. package/dist/node/axios.cjs.map +1 -1
  16. package/index.d.cts +528 -0
  17. package/index.d.ts +116 -56
  18. package/index.js +12 -3
  19. package/lib/adapters/adapters.js +59 -0
  20. package/lib/adapters/http.js +87 -34
  21. package/lib/adapters/xhr.js +7 -4
  22. package/lib/axios.js +13 -3
  23. package/lib/core/Axios.js +10 -8
  24. package/lib/core/AxiosError.js +1 -1
  25. package/lib/core/AxiosHeaders.js +102 -80
  26. package/lib/core/dispatchRequest.js +7 -2
  27. package/lib/core/mergeConfig.js +50 -46
  28. package/lib/defaults/index.js +2 -21
  29. package/lib/env/classes/FormData.js +2 -2
  30. package/lib/env/data.js +1 -1
  31. package/lib/helpers/HttpStatusCode.js +71 -0
  32. package/lib/helpers/ZlibHeaderTransformStream.js +28 -0
  33. package/lib/helpers/formDataToStream.js +111 -0
  34. package/lib/helpers/readBlob.js +15 -0
  35. package/lib/helpers/speedometer.js +1 -1
  36. package/lib/helpers/toFormData.js +5 -15
  37. package/lib/platform/browser/classes/FormData.js +1 -1
  38. package/lib/platform/browser/index.js +20 -0
  39. package/lib/utils.js +107 -9
  40. package/package.json +86 -14
  41. package/bin/ssl_hotfix.js +0 -22
  42. package/gulpfile.js +0 -88
  43. package/karma.conf.cjs +0 -250
  44. package/lib/adapters/index.js +0 -33
  45. package/rollup.config.js +0 -90
  46. package/tsconfig.json +0 -14
  47. package/tslint.json +0 -6
@@ -1,4 +1,4 @@
1
- // Axios v1.1.3 Copyright (c) 2022 Matt Zabriskie and contributors
1
+ // Axios v1.3.3 Copyright (c) 2023 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -6,6 +6,7 @@ const url = require('url');
6
6
  const proxyFromEnv = require('proxy-from-env');
7
7
  const http = require('http');
8
8
  const https = require('https');
9
+ const util = require('util');
9
10
  const followRedirects = require('follow-redirects');
10
11
  const zlib = require('zlib');
11
12
  const stream = require('stream');
@@ -17,6 +18,7 @@ const FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData$1);
17
18
  const url__default = /*#__PURE__*/_interopDefaultLegacy(url);
18
19
  const http__default = /*#__PURE__*/_interopDefaultLegacy(http);
19
20
  const https__default = /*#__PURE__*/_interopDefaultLegacy(https);
21
+ const util__default = /*#__PURE__*/_interopDefaultLegacy(util);
20
22
  const followRedirects__default = /*#__PURE__*/_interopDefaultLegacy(followRedirects);
21
23
  const zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
22
24
  const stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
@@ -254,7 +256,7 @@ const trim = (str) => str.trim ?
254
256
  * @param {Function} fn The callback to invoke for each item
255
257
  *
256
258
  * @param {Boolean} [allOwnKeys = false]
257
- * @returns {void}
259
+ * @returns {any}
258
260
  */
259
261
  function forEach(obj, fn, {allOwnKeys = false} = {}) {
260
262
  // Don't bother if no value provided
@@ -289,6 +291,28 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
289
291
  }
290
292
  }
291
293
 
294
+ function findKey(obj, key) {
295
+ key = key.toLowerCase();
296
+ const keys = Object.keys(obj);
297
+ let i = keys.length;
298
+ let _key;
299
+ while (i-- > 0) {
300
+ _key = keys[i];
301
+ if (key === _key.toLowerCase()) {
302
+ return _key;
303
+ }
304
+ }
305
+ return null;
306
+ }
307
+
308
+ const _global = (() => {
309
+ /*eslint no-undef:0*/
310
+ if (typeof globalThis !== "undefined") return globalThis;
311
+ return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)
312
+ })();
313
+
314
+ const isContextDefined = (context) => !isUndefined(context) && context !== _global;
315
+
292
316
  /**
293
317
  * Accepts varargs expecting each argument to be an object, then
294
318
  * immutably merges the properties of each object and returns result.
@@ -308,16 +332,18 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
308
332
  * @returns {Object} Result of all merge properties
309
333
  */
310
334
  function merge(/* obj1, obj2, obj3, ... */) {
335
+ const {caseless} = isContextDefined(this) && this || {};
311
336
  const result = {};
312
337
  const assignValue = (val, key) => {
313
- if (isPlainObject(result[key]) && isPlainObject(val)) {
314
- result[key] = merge(result[key], val);
338
+ const targetKey = caseless && findKey(result, key) || key;
339
+ if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
340
+ result[targetKey] = merge(result[targetKey], val);
315
341
  } else if (isPlainObject(val)) {
316
- result[key] = merge({}, val);
342
+ result[targetKey] = merge({}, val);
317
343
  } else if (isArray(val)) {
318
- result[key] = val.slice();
344
+ result[targetKey] = val.slice();
319
345
  } else {
320
- result[key] = val;
346
+ result[targetKey] = val;
321
347
  }
322
348
  };
323
349
 
@@ -514,7 +540,7 @@ const matchAll = (regExp, str) => {
514
540
  const isHTMLForm = kindOfTest('HTMLFormElement');
515
541
 
516
542
  const toCamelCase = str => {
517
- return str.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,
543
+ return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,
518
544
  function replacer(m, p1, p2) {
519
545
  return p1.toUpperCase() + p2;
520
546
  }
@@ -553,6 +579,11 @@ const reduceDescriptors = (obj, reducer) => {
553
579
 
554
580
  const freezeMethods = (obj) => {
555
581
  reduceDescriptors(obj, (descriptor, name) => {
582
+ // skip restricted props in strict mode
583
+ if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
584
+ return false;
585
+ }
586
+
556
587
  const value = obj[name];
557
588
 
558
589
  if (!isFunction(value)) return;
@@ -566,7 +597,7 @@ const freezeMethods = (obj) => {
566
597
 
567
598
  if (!descriptor.set) {
568
599
  descriptor.set = () => {
569
- throw Error('Can not read-only method \'' + name + '\'');
600
+ throw Error('Can not rewrite read-only method \'' + name + '\'');
570
601
  };
571
602
  }
572
603
  });
@@ -593,6 +624,68 @@ const toFiniteNumber = (value, defaultValue) => {
593
624
  return Number.isFinite(value) ? value : defaultValue;
594
625
  };
595
626
 
627
+ const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
628
+
629
+ const DIGIT = '0123456789';
630
+
631
+ const ALPHABET = {
632
+ DIGIT,
633
+ ALPHA,
634
+ ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
635
+ };
636
+
637
+ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
638
+ let str = '';
639
+ const {length} = alphabet;
640
+ while (size--) {
641
+ str += alphabet[Math.random() * length|0];
642
+ }
643
+
644
+ return str;
645
+ };
646
+
647
+ /**
648
+ * If the thing is a FormData object, return true, otherwise return false.
649
+ *
650
+ * @param {unknown} thing - The thing to check.
651
+ *
652
+ * @returns {boolean}
653
+ */
654
+ function isSpecCompliantForm(thing) {
655
+ return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
656
+ }
657
+
658
+ const toJSONObject = (obj) => {
659
+ const stack = new Array(10);
660
+
661
+ const visit = (source, i) => {
662
+
663
+ if (isObject(source)) {
664
+ if (stack.indexOf(source) >= 0) {
665
+ return;
666
+ }
667
+
668
+ if(!('toJSON' in source)) {
669
+ stack[i] = source;
670
+ const target = isArray(source) ? [] : {};
671
+
672
+ forEach(source, (value, key) => {
673
+ const reducedValue = visit(value, i + 1);
674
+ !isUndefined(reducedValue) && (target[key] = reducedValue);
675
+ });
676
+
677
+ stack[i] = undefined;
678
+
679
+ return target;
680
+ }
681
+ }
682
+
683
+ return source;
684
+ };
685
+
686
+ return visit(obj, 0);
687
+ };
688
+
596
689
  const utils = {
597
690
  isArray,
598
691
  isArrayBuffer,
@@ -635,7 +728,14 @@ const utils = {
635
728
  toObjectSet,
636
729
  toCamelCase,
637
730
  noop,
638
- toFiniteNumber
731
+ toFiniteNumber,
732
+ findKey,
733
+ global: _global,
734
+ isContextDefined,
735
+ ALPHABET,
736
+ generateString,
737
+ isSpecCompliantForm,
738
+ toJSONObject
639
739
  };
640
740
 
641
741
  /**
@@ -681,7 +781,7 @@ utils.inherits(AxiosError, Error, {
681
781
  columnNumber: this.columnNumber,
682
782
  stack: this.stack,
683
783
  // Axios
684
- config: this.config,
784
+ config: utils.toJSONObject(this.config),
685
785
  code: this.code,
686
786
  status: this.response && this.response.status ? this.response.status : null
687
787
  };
@@ -788,17 +888,6 @@ const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
788
888
  return /^is[A-Z]/.test(prop);
789
889
  });
790
890
 
791
- /**
792
- * If the thing is a FormData object, return true, otherwise return false.
793
- *
794
- * @param {unknown} thing - The thing to check.
795
- *
796
- * @returns {boolean}
797
- */
798
- function isSpecCompliant(thing) {
799
- return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
800
- }
801
-
802
891
  /**
803
892
  * Convert a data object to FormData
804
893
  *
@@ -846,7 +935,7 @@ function toFormData(obj, formData, options) {
846
935
  const dots = options.dots;
847
936
  const indexes = options.indexes;
848
937
  const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
849
- const useBlob = _Blob && isSpecCompliant(formData);
938
+ const useBlob = _Blob && utils.isSpecCompliantForm(formData);
850
939
 
851
940
  if (!utils.isFunction(visitor)) {
852
941
  throw new TypeError('visitor must be a function');
@@ -891,7 +980,7 @@ function toFormData(obj, formData, options) {
891
980
  value = JSON.stringify(value);
892
981
  } else if (
893
982
  (utils.isArray(value) && isFlatArray(value)) ||
894
- (utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
983
+ ((utils.isFileList(value) || utils.endsWith(key, '[]')) && (arr = utils.toArray(value))
895
984
  )) {
896
985
  // eslint-disable-next-line no-param-reassign
897
986
  key = removeBrackets(key);
@@ -1133,6 +1222,8 @@ class InterceptorManager {
1133
1222
  }
1134
1223
  }
1135
1224
 
1225
+ const InterceptorManager$1 = InterceptorManager;
1226
+
1136
1227
  const transitionalDefaults = {
1137
1228
  silentJSONParsing: true,
1138
1229
  forcedJSONParsing: true,
@@ -1251,157 +1342,171 @@ function formDataToJSON(formData) {
1251
1342
  return null;
1252
1343
  }
1253
1344
 
1254
- /**
1255
- * Resolve or reject a Promise based on response status.
1256
- *
1257
- * @param {Function} resolve A function that resolves the promise.
1258
- * @param {Function} reject A function that rejects the promise.
1259
- * @param {object} response The response.
1260
- *
1261
- * @returns {object} The response.
1262
- */
1263
- function settle(resolve, reject, response) {
1264
- const validateStatus = response.config.validateStatus;
1265
- if (!response.status || !validateStatus || validateStatus(response.status)) {
1266
- resolve(response);
1267
- } else {
1268
- reject(new AxiosError(
1269
- 'Request failed with status code ' + response.status,
1270
- [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1271
- response.config,
1272
- response.request,
1273
- response
1274
- ));
1275
- }
1276
- }
1277
-
1278
- /**
1279
- * Determines whether the specified URL is absolute
1280
- *
1281
- * @param {string} url The URL to test
1282
- *
1283
- * @returns {boolean} True if the specified URL is absolute, otherwise false
1284
- */
1285
- function isAbsoluteURL(url) {
1286
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1287
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1288
- // by any combination of letters, digits, plus, period, or hyphen.
1289
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1290
- }
1291
-
1292
- /**
1293
- * Creates a new URL by combining the specified URLs
1294
- *
1295
- * @param {string} baseURL The base URL
1296
- * @param {string} relativeURL The relative URL
1297
- *
1298
- * @returns {string} The combined URL
1299
- */
1300
- function combineURLs(baseURL, relativeURL) {
1301
- return relativeURL
1302
- ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1303
- : baseURL;
1304
- }
1345
+ const DEFAULT_CONTENT_TYPE = {
1346
+ 'Content-Type': undefined
1347
+ };
1305
1348
 
1306
1349
  /**
1307
- * Creates a new URL by combining the baseURL with the requestedURL,
1308
- * only when the requestedURL is not already an absolute URL.
1309
- * If the requestURL is absolute, this function returns the requestedURL untouched.
1350
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1351
+ * of the input
1310
1352
  *
1311
- * @param {string} baseURL The base URL
1312
- * @param {string} requestedURL Absolute or relative URL to combine
1353
+ * @param {any} rawValue - The value to be stringified.
1354
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
1355
+ * @param {Function} encoder - A function that takes a value and returns a string.
1313
1356
  *
1314
- * @returns {string} The combined full path
1357
+ * @returns {string} A stringified version of the rawValue.
1315
1358
  */
1316
- function buildFullPath(baseURL, requestedURL) {
1317
- if (baseURL && !isAbsoluteURL(requestedURL)) {
1318
- return combineURLs(baseURL, requestedURL);
1359
+ function stringifySafely(rawValue, parser, encoder) {
1360
+ if (utils.isString(rawValue)) {
1361
+ try {
1362
+ (parser || JSON.parse)(rawValue);
1363
+ return utils.trim(rawValue);
1364
+ } catch (e) {
1365
+ if (e.name !== 'SyntaxError') {
1366
+ throw e;
1367
+ }
1368
+ }
1319
1369
  }
1320
- return requestedURL;
1321
- }
1322
-
1323
- const VERSION = "1.1.3";
1324
1370
 
1325
- /**
1326
- * A `CanceledError` is an object that is thrown when an operation is canceled.
1327
- *
1328
- * @param {string=} message The message.
1329
- * @param {Object=} config The config.
1330
- * @param {Object=} request The request.
1331
- *
1332
- * @returns {CanceledError} The created error.
1333
- */
1334
- function CanceledError(message, config, request) {
1335
- // eslint-disable-next-line no-eq-null,eqeqeq
1336
- AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1337
- this.name = 'CanceledError';
1371
+ return (encoder || JSON.stringify)(rawValue);
1338
1372
  }
1339
1373
 
1340
- utils.inherits(CanceledError, AxiosError, {
1341
- __CANCEL__: true
1342
- });
1374
+ const defaults = {
1343
1375
 
1344
- function parseProtocol(url) {
1345
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1346
- return match && match[1] || '';
1347
- }
1376
+ transitional: transitionalDefaults,
1348
1377
 
1349
- const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
1378
+ adapter: ['xhr', 'http'],
1350
1379
 
1351
- /**
1352
- * Parse data uri to a Buffer or Blob
1353
- *
1354
- * @param {String} uri
1355
- * @param {?Boolean} asBlob
1356
- * @param {?Object} options
1357
- * @param {?Function} options.Blob
1358
- *
1359
- * @returns {Buffer|Blob}
1360
- */
1361
- function fromDataURI(uri, asBlob, options) {
1362
- const _Blob = options && options.Blob || platform.classes.Blob;
1363
- const protocol = parseProtocol(uri);
1380
+ transformRequest: [function transformRequest(data, headers) {
1381
+ const contentType = headers.getContentType() || '';
1382
+ const hasJSONContentType = contentType.indexOf('application/json') > -1;
1383
+ const isObjectPayload = utils.isObject(data);
1364
1384
 
1365
- if (asBlob === undefined && _Blob) {
1366
- asBlob = true;
1367
- }
1385
+ if (isObjectPayload && utils.isHTMLForm(data)) {
1386
+ data = new FormData(data);
1387
+ }
1368
1388
 
1369
- if (protocol === 'data') {
1370
- uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
1389
+ const isFormData = utils.isFormData(data);
1371
1390
 
1372
- const match = DATA_URL_PATTERN.exec(uri);
1391
+ if (isFormData) {
1392
+ if (!hasJSONContentType) {
1393
+ return data;
1394
+ }
1395
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1396
+ }
1373
1397
 
1374
- if (!match) {
1375
- throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
1398
+ if (utils.isArrayBuffer(data) ||
1399
+ utils.isBuffer(data) ||
1400
+ utils.isStream(data) ||
1401
+ utils.isFile(data) ||
1402
+ utils.isBlob(data)
1403
+ ) {
1404
+ return data;
1405
+ }
1406
+ if (utils.isArrayBufferView(data)) {
1407
+ return data.buffer;
1408
+ }
1409
+ if (utils.isURLSearchParams(data)) {
1410
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1411
+ return data.toString();
1376
1412
  }
1377
1413
 
1378
- const mime = match[1];
1379
- const isBase64 = match[2];
1380
- const body = match[3];
1381
- const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
1414
+ let isFileList;
1382
1415
 
1383
- if (asBlob) {
1384
- if (!_Blob) {
1385
- throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
1416
+ if (isObjectPayload) {
1417
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1418
+ return toURLEncodedForm(data, this.formSerializer).toString();
1386
1419
  }
1387
1420
 
1388
- return new _Blob([buffer], {type: mime});
1421
+ if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1422
+ const _FormData = this.env && this.env.FormData;
1423
+
1424
+ return toFormData(
1425
+ isFileList ? {'files[]': data} : data,
1426
+ _FormData && new _FormData(),
1427
+ this.formSerializer
1428
+ );
1429
+ }
1389
1430
  }
1390
1431
 
1391
- return buffer;
1392
- }
1432
+ if (isObjectPayload || hasJSONContentType ) {
1433
+ headers.setContentType('application/json', false);
1434
+ return stringifySafely(data);
1435
+ }
1393
1436
 
1394
- throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
1395
- }
1437
+ return data;
1438
+ }],
1396
1439
 
1397
- // RawAxiosHeaders whose duplicates are ignored by node
1398
- // c.f. https://nodejs.org/api/http.html#http_message_headers
1399
- const ignoreDuplicateOf = utils.toObjectSet([
1400
- 'age', 'authorization', 'content-length', 'content-type', 'etag',
1401
- 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
1402
- 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
1403
- 'referer', 'retry-after', 'user-agent'
1404
- ]);
1440
+ transformResponse: [function transformResponse(data) {
1441
+ const transitional = this.transitional || defaults.transitional;
1442
+ const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1443
+ const JSONRequested = this.responseType === 'json';
1444
+
1445
+ if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1446
+ const silentJSONParsing = transitional && transitional.silentJSONParsing;
1447
+ const strictJSONParsing = !silentJSONParsing && JSONRequested;
1448
+
1449
+ try {
1450
+ return JSON.parse(data);
1451
+ } catch (e) {
1452
+ if (strictJSONParsing) {
1453
+ if (e.name === 'SyntaxError') {
1454
+ throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
1455
+ }
1456
+ throw e;
1457
+ }
1458
+ }
1459
+ }
1460
+
1461
+ return data;
1462
+ }],
1463
+
1464
+ /**
1465
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
1466
+ * timeout is not created.
1467
+ */
1468
+ timeout: 0,
1469
+
1470
+ xsrfCookieName: 'XSRF-TOKEN',
1471
+ xsrfHeaderName: 'X-XSRF-TOKEN',
1472
+
1473
+ maxContentLength: -1,
1474
+ maxBodyLength: -1,
1475
+
1476
+ env: {
1477
+ FormData: platform.classes.FormData,
1478
+ Blob: platform.classes.Blob
1479
+ },
1480
+
1481
+ validateStatus: function validateStatus(status) {
1482
+ return status >= 200 && status < 300;
1483
+ },
1484
+
1485
+ headers: {
1486
+ common: {
1487
+ 'Accept': 'application/json, text/plain, */*'
1488
+ }
1489
+ }
1490
+ };
1491
+
1492
+ utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1493
+ defaults.headers[method] = {};
1494
+ });
1495
+
1496
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1497
+ defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1498
+ });
1499
+
1500
+ const defaults$1 = defaults;
1501
+
1502
+ // RawAxiosHeaders whose duplicates are ignored by node
1503
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
1504
+ const ignoreDuplicateOf = utils.toObjectSet([
1505
+ 'age', 'authorization', 'content-length', 'content-type', 'etag',
1506
+ 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
1507
+ 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
1508
+ 'referer', 'retry-after', 'user-agent'
1509
+ ]);
1405
1510
 
1406
1511
  /**
1407
1512
  * Parse headers into an object
@@ -1447,7 +1552,6 @@ const parseHeaders = rawHeaders => {
1447
1552
  };
1448
1553
 
1449
1554
  const $internals = Symbol('internals');
1450
- const $defaults = Symbol('defaults');
1451
1555
 
1452
1556
  function normalizeHeader(header) {
1453
1557
  return header && String(header).trim().toLowerCase();
@@ -1473,11 +1577,19 @@ function parseTokens(str) {
1473
1577
  return tokens;
1474
1578
  }
1475
1579
 
1476
- function matchHeaderValue(context, value, header, filter) {
1580
+ function isValidHeaderName(str) {
1581
+ return /^[-_a-zA-Z]+$/.test(str.trim());
1582
+ }
1583
+
1584
+ function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
1477
1585
  if (utils.isFunction(filter)) {
1478
1586
  return filter.call(this, value, header);
1479
1587
  }
1480
1588
 
1589
+ if (isHeaderNameFilter) {
1590
+ value = header;
1591
+ }
1592
+
1481
1593
  if (!utils.isString(value)) return;
1482
1594
 
1483
1595
  if (utils.isString(filter)) {
@@ -1509,27 +1621,12 @@ function buildAccessors(obj, header) {
1509
1621
  });
1510
1622
  }
1511
1623
 
1512
- function findKey(obj, key) {
1513
- key = key.toLowerCase();
1514
- const keys = Object.keys(obj);
1515
- let i = keys.length;
1516
- let _key;
1517
- while (i-- > 0) {
1518
- _key = keys[i];
1519
- if (key === _key.toLowerCase()) {
1520
- return _key;
1521
- }
1624
+ class AxiosHeaders {
1625
+ constructor(headers) {
1626
+ headers && this.set(headers);
1522
1627
  }
1523
- return null;
1524
- }
1525
1628
 
1526
- function AxiosHeaders(headers, defaults) {
1527
- headers && this.set(headers);
1528
- this[$defaults] = defaults || null;
1529
- }
1530
-
1531
- Object.assign(AxiosHeaders.prototype, {
1532
- set: function(header, valueOrRewrite, rewrite) {
1629
+ set(header, valueOrRewrite, rewrite) {
1533
1630
  const self = this;
1534
1631
 
1535
1632
  function setHeader(_value, _header, _rewrite) {
@@ -1539,69 +1636,70 @@ Object.assign(AxiosHeaders.prototype, {
1539
1636
  throw new Error('header name must be a non-empty string');
1540
1637
  }
1541
1638
 
1542
- const key = findKey(self, lHeader);
1639
+ const key = utils.findKey(self, lHeader);
1543
1640
 
1544
- if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
1545
- return;
1641
+ if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
1642
+ self[key || _header] = normalizeValue(_value);
1546
1643
  }
1547
-
1548
- self[key || _header] = normalizeValue(_value);
1549
1644
  }
1550
1645
 
1551
- if (utils.isPlainObject(header)) {
1552
- utils.forEach(header, (_value, _header) => {
1553
- setHeader(_value, _header, valueOrRewrite);
1554
- });
1646
+ const setHeaders = (headers, _rewrite) =>
1647
+ utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
1648
+
1649
+ if (utils.isPlainObject(header) || header instanceof this.constructor) {
1650
+ setHeaders(header, valueOrRewrite);
1651
+ } else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1652
+ setHeaders(parseHeaders(header), valueOrRewrite);
1555
1653
  } else {
1556
- setHeader(valueOrRewrite, header, rewrite);
1654
+ header != null && setHeader(valueOrRewrite, header, rewrite);
1557
1655
  }
1558
1656
 
1559
1657
  return this;
1560
- },
1658
+ }
1561
1659
 
1562
- get: function(header, parser) {
1660
+ get(header, parser) {
1563
1661
  header = normalizeHeader(header);
1564
1662
 
1565
- if (!header) return undefined;
1663
+ if (header) {
1664
+ const key = utils.findKey(this, header);
1566
1665
 
1567
- const key = findKey(this, header);
1666
+ if (key) {
1667
+ const value = this[key];
1568
1668
 
1569
- if (key) {
1570
- const value = this[key];
1669
+ if (!parser) {
1670
+ return value;
1671
+ }
1571
1672
 
1572
- if (!parser) {
1573
- return value;
1574
- }
1673
+ if (parser === true) {
1674
+ return parseTokens(value);
1675
+ }
1575
1676
 
1576
- if (parser === true) {
1577
- return parseTokens(value);
1578
- }
1677
+ if (utils.isFunction(parser)) {
1678
+ return parser.call(this, value, key);
1679
+ }
1579
1680
 
1580
- if (utils.isFunction(parser)) {
1581
- return parser.call(this, value, key);
1582
- }
1681
+ if (utils.isRegExp(parser)) {
1682
+ return parser.exec(value);
1683
+ }
1583
1684
 
1584
- if (utils.isRegExp(parser)) {
1585
- return parser.exec(value);
1685
+ throw new TypeError('parser must be boolean|regexp|function');
1586
1686
  }
1587
-
1588
- throw new TypeError('parser must be boolean|regexp|function');
1589
1687
  }
1590
- },
1688
+ }
1591
1689
 
1592
- has: function(header, matcher) {
1690
+ has(header, matcher) {
1593
1691
  header = normalizeHeader(header);
1594
1692
 
1595
1693
  if (header) {
1596
- const key = findKey(this, header);
1694
+ const key = utils.findKey(this, header);
1597
1695
 
1598
- return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1696
+ return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1599
1697
  }
1600
1698
 
1601
1699
  return false;
1602
- },
1700
+ }
1603
1701
 
1604
- delete: function(header, matcher) {
1702
+ delete(header, matcher) {
1605
1703
  const self = this;
1606
1704
  let deleted = false;
1607
1705
 
@@ -1609,7 +1707,7 @@ Object.assign(AxiosHeaders.prototype, {
1609
1707
  _header = normalizeHeader(_header);
1610
1708
 
1611
1709
  if (_header) {
1612
- const key = findKey(self, _header);
1710
+ const key = utils.findKey(self, _header);
1613
1711
 
1614
1712
  if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1615
1713
  delete self[key];
@@ -1626,18 +1724,30 @@ Object.assign(AxiosHeaders.prototype, {
1626
1724
  }
1627
1725
 
1628
1726
  return deleted;
1629
- },
1727
+ }
1630
1728
 
1631
- clear: function() {
1632
- return Object.keys(this).forEach(this.delete.bind(this));
1633
- },
1729
+ clear(matcher) {
1730
+ const keys = Object.keys(this);
1731
+ let i = keys.length;
1732
+ let deleted = false;
1733
+
1734
+ while (i--) {
1735
+ const key = keys[i];
1736
+ if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
1737
+ delete this[key];
1738
+ deleted = true;
1739
+ }
1740
+ }
1741
+
1742
+ return deleted;
1743
+ }
1634
1744
 
1635
- normalize: function(format) {
1745
+ normalize(format) {
1636
1746
  const self = this;
1637
1747
  const headers = {};
1638
1748
 
1639
1749
  utils.forEach(this, (value, header) => {
1640
- const key = findKey(headers, header);
1750
+ const key = utils.findKey(headers, header);
1641
1751
 
1642
1752
  if (key) {
1643
1753
  self[key] = normalizeValue(value);
@@ -1657,30 +1767,47 @@ Object.assign(AxiosHeaders.prototype, {
1657
1767
  });
1658
1768
 
1659
1769
  return this;
1660
- },
1770
+ }
1661
1771
 
1662
- toJSON: function(asStrings) {
1772
+ concat(...targets) {
1773
+ return this.constructor.concat(this, ...targets);
1774
+ }
1775
+
1776
+ toJSON(asStrings) {
1663
1777
  const obj = Object.create(null);
1664
1778
 
1665
- utils.forEach(Object.assign({}, this[$defaults] || null, this),
1666
- (value, header) => {
1667
- if (value == null || value === false) return;
1668
- obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
1669
- });
1779
+ utils.forEach(this, (value, header) => {
1780
+ value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
1781
+ });
1670
1782
 
1671
1783
  return obj;
1672
1784
  }
1673
- });
1674
1785
 
1675
- Object.assign(AxiosHeaders, {
1676
- from: function(thing) {
1677
- if (utils.isString(thing)) {
1678
- return new this(parseHeaders(thing));
1679
- }
1786
+ [Symbol.iterator]() {
1787
+ return Object.entries(this.toJSON())[Symbol.iterator]();
1788
+ }
1789
+
1790
+ toString() {
1791
+ return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
1792
+ }
1793
+
1794
+ get [Symbol.toStringTag]() {
1795
+ return 'AxiosHeaders';
1796
+ }
1797
+
1798
+ static from(thing) {
1680
1799
  return thing instanceof this ? thing : new this(thing);
1681
- },
1800
+ }
1682
1801
 
1683
- accessor: function(header) {
1802
+ static concat(first, ...targets) {
1803
+ const computed = new this(first);
1804
+
1805
+ targets.forEach((target) => computed.set(target));
1806
+
1807
+ return computed;
1808
+ }
1809
+
1810
+ static accessor(header) {
1684
1811
  const internals = this[$internals] = (this[$internals] = {
1685
1812
  accessors: {}
1686
1813
  });
@@ -1701,13 +1828,185 @@ Object.assign(AxiosHeaders, {
1701
1828
 
1702
1829
  return this;
1703
1830
  }
1704
- });
1831
+ }
1705
1832
 
1706
- AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1833
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1707
1834
 
1708
1835
  utils.freezeMethods(AxiosHeaders.prototype);
1709
1836
  utils.freezeMethods(AxiosHeaders);
1710
1837
 
1838
+ const AxiosHeaders$1 = AxiosHeaders;
1839
+
1840
+ /**
1841
+ * Transform the data for a request or a response
1842
+ *
1843
+ * @param {Array|Function} fns A single function or Array of functions
1844
+ * @param {?Object} response The response object
1845
+ *
1846
+ * @returns {*} The resulting transformed data
1847
+ */
1848
+ function transformData(fns, response) {
1849
+ const config = this || defaults$1;
1850
+ const context = response || config;
1851
+ const headers = AxiosHeaders$1.from(context.headers);
1852
+ let data = context.data;
1853
+
1854
+ utils.forEach(fns, function transform(fn) {
1855
+ data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
1856
+ });
1857
+
1858
+ headers.normalize();
1859
+
1860
+ return data;
1861
+ }
1862
+
1863
+ function isCancel(value) {
1864
+ return !!(value && value.__CANCEL__);
1865
+ }
1866
+
1867
+ /**
1868
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
1869
+ *
1870
+ * @param {string=} message The message.
1871
+ * @param {Object=} config The config.
1872
+ * @param {Object=} request The request.
1873
+ *
1874
+ * @returns {CanceledError} The created error.
1875
+ */
1876
+ function CanceledError(message, config, request) {
1877
+ // eslint-disable-next-line no-eq-null,eqeqeq
1878
+ AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1879
+ this.name = 'CanceledError';
1880
+ }
1881
+
1882
+ utils.inherits(CanceledError, AxiosError, {
1883
+ __CANCEL__: true
1884
+ });
1885
+
1886
+ /**
1887
+ * Resolve or reject a Promise based on response status.
1888
+ *
1889
+ * @param {Function} resolve A function that resolves the promise.
1890
+ * @param {Function} reject A function that rejects the promise.
1891
+ * @param {object} response The response.
1892
+ *
1893
+ * @returns {object} The response.
1894
+ */
1895
+ function settle(resolve, reject, response) {
1896
+ const validateStatus = response.config.validateStatus;
1897
+ if (!response.status || !validateStatus || validateStatus(response.status)) {
1898
+ resolve(response);
1899
+ } else {
1900
+ reject(new AxiosError(
1901
+ 'Request failed with status code ' + response.status,
1902
+ [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1903
+ response.config,
1904
+ response.request,
1905
+ response
1906
+ ));
1907
+ }
1908
+ }
1909
+
1910
+ /**
1911
+ * Determines whether the specified URL is absolute
1912
+ *
1913
+ * @param {string} url The URL to test
1914
+ *
1915
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
1916
+ */
1917
+ function isAbsoluteURL(url) {
1918
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1919
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1920
+ // by any combination of letters, digits, plus, period, or hyphen.
1921
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1922
+ }
1923
+
1924
+ /**
1925
+ * Creates a new URL by combining the specified URLs
1926
+ *
1927
+ * @param {string} baseURL The base URL
1928
+ * @param {string} relativeURL The relative URL
1929
+ *
1930
+ * @returns {string} The combined URL
1931
+ */
1932
+ function combineURLs(baseURL, relativeURL) {
1933
+ return relativeURL
1934
+ ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1935
+ : baseURL;
1936
+ }
1937
+
1938
+ /**
1939
+ * Creates a new URL by combining the baseURL with the requestedURL,
1940
+ * only when the requestedURL is not already an absolute URL.
1941
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
1942
+ *
1943
+ * @param {string} baseURL The base URL
1944
+ * @param {string} requestedURL Absolute or relative URL to combine
1945
+ *
1946
+ * @returns {string} The combined full path
1947
+ */
1948
+ function buildFullPath(baseURL, requestedURL) {
1949
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
1950
+ return combineURLs(baseURL, requestedURL);
1951
+ }
1952
+ return requestedURL;
1953
+ }
1954
+
1955
+ const VERSION = "1.3.3";
1956
+
1957
+ function parseProtocol(url) {
1958
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1959
+ return match && match[1] || '';
1960
+ }
1961
+
1962
+ const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
1963
+
1964
+ /**
1965
+ * Parse data uri to a Buffer or Blob
1966
+ *
1967
+ * @param {String} uri
1968
+ * @param {?Boolean} asBlob
1969
+ * @param {?Object} options
1970
+ * @param {?Function} options.Blob
1971
+ *
1972
+ * @returns {Buffer|Blob}
1973
+ */
1974
+ function fromDataURI(uri, asBlob, options) {
1975
+ const _Blob = options && options.Blob || platform.classes.Blob;
1976
+ const protocol = parseProtocol(uri);
1977
+
1978
+ if (asBlob === undefined && _Blob) {
1979
+ asBlob = true;
1980
+ }
1981
+
1982
+ if (protocol === 'data') {
1983
+ uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
1984
+
1985
+ const match = DATA_URL_PATTERN.exec(uri);
1986
+
1987
+ if (!match) {
1988
+ throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
1989
+ }
1990
+
1991
+ const mime = match[1];
1992
+ const isBase64 = match[2];
1993
+ const body = match[3];
1994
+ const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
1995
+
1996
+ if (asBlob) {
1997
+ if (!_Blob) {
1998
+ throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
1999
+ }
2000
+
2001
+ return new _Blob([buffer], {type: mime});
2002
+ }
2003
+
2004
+ return buffer;
2005
+ }
2006
+
2007
+ throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
2008
+ }
2009
+
1711
2010
  /**
1712
2011
  * Throttle decorator
1713
2012
  * @param {Function} fn
@@ -1786,7 +2085,7 @@ function speedometer(samplesCount, min) {
1786
2085
 
1787
2086
  const passed = startedAt && now - startedAt;
1788
2087
 
1789
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2088
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
1790
2089
  };
1791
2090
  }
1792
2091
 
@@ -1967,12 +2266,172 @@ class AxiosTransformStream extends stream__default["default"].Transform{
1967
2266
  });
1968
2267
  }
1969
2268
 
1970
- setLength(length) {
1971
- this[kInternals].length = +length;
1972
- return this;
2269
+ setLength(length) {
2270
+ this[kInternals].length = +length;
2271
+ return this;
2272
+ }
2273
+ }
2274
+
2275
+ const AxiosTransformStream$1 = AxiosTransformStream;
2276
+
2277
+ const {asyncIterator} = Symbol;
2278
+
2279
+ const readBlob = async function* (blob) {
2280
+ if (blob.stream) {
2281
+ yield* blob.stream();
2282
+ } else if (blob.arrayBuffer) {
2283
+ yield await blob.arrayBuffer();
2284
+ } else if (blob[asyncIterator]) {
2285
+ yield* blob[asyncIterator]();
2286
+ } else {
2287
+ yield blob;
2288
+ }
2289
+ };
2290
+
2291
+ const readBlob$1 = readBlob;
2292
+
2293
+ const BOUNDARY_ALPHABET = utils.ALPHABET.ALPHA_DIGIT + '-_';
2294
+
2295
+ const textEncoder = new util.TextEncoder();
2296
+
2297
+ const CRLF = '\r\n';
2298
+ const CRLF_BYTES = textEncoder.encode(CRLF);
2299
+ const CRLF_BYTES_COUNT = 2;
2300
+
2301
+ class FormDataPart {
2302
+ constructor(name, value) {
2303
+ const {escapeName} = this.constructor;
2304
+ const isStringValue = utils.isString(value);
2305
+
2306
+ let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
2307
+ !isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''
2308
+ }${CRLF}`;
2309
+
2310
+ if (isStringValue) {
2311
+ value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
2312
+ } else {
2313
+ headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}`;
2314
+ }
2315
+
2316
+ this.headers = textEncoder.encode(headers + CRLF);
2317
+
2318
+ this.contentLength = isStringValue ? value.byteLength : value.size;
2319
+
2320
+ this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
2321
+
2322
+ this.name = name;
2323
+ this.value = value;
2324
+ }
2325
+
2326
+ async *encode(){
2327
+ yield this.headers;
2328
+
2329
+ const {value} = this;
2330
+
2331
+ if(utils.isTypedArray(value)) {
2332
+ yield value;
2333
+ } else {
2334
+ yield* readBlob$1(value);
2335
+ }
2336
+
2337
+ yield CRLF_BYTES;
2338
+ }
2339
+
2340
+ static escapeName(name) {
2341
+ return String(name).replace(/[\r\n"]/g, (match) => ({
2342
+ '\r' : '%0D',
2343
+ '\n' : '%0A',
2344
+ '"' : '%22',
2345
+ }[match]));
2346
+ }
2347
+ }
2348
+
2349
+ const formDataToStream = (form, headersHandler, options) => {
2350
+ const {
2351
+ tag = 'form-data-boundary',
2352
+ size = 25,
2353
+ boundary = tag + '-' + utils.generateString(size, BOUNDARY_ALPHABET)
2354
+ } = options || {};
2355
+
2356
+ if(!utils.isFormData(form)) {
2357
+ throw TypeError('FormData instance required');
2358
+ }
2359
+
2360
+ if (boundary.length < 1 || boundary.length > 70) {
2361
+ throw Error('boundary must be 10-70 characters long')
2362
+ }
2363
+
2364
+ const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
2365
+ const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF + CRLF);
2366
+ let contentLength = footerBytes.byteLength;
2367
+
2368
+ const parts = Array.from(form.entries()).map(([name, value]) => {
2369
+ const part = new FormDataPart(name, value);
2370
+ contentLength += part.size;
2371
+ return part;
2372
+ });
2373
+
2374
+ contentLength += boundaryBytes.byteLength * parts.length;
2375
+
2376
+ contentLength = utils.toFiniteNumber(contentLength);
2377
+
2378
+ const computedHeaders = {
2379
+ 'Content-Type': `multipart/form-data; boundary=${boundary}`
2380
+ };
2381
+
2382
+ if (Number.isFinite(contentLength)) {
2383
+ computedHeaders['Content-Length'] = contentLength;
2384
+ }
2385
+
2386
+ headersHandler && headersHandler(computedHeaders);
2387
+
2388
+ return stream.Readable.from((async function *() {
2389
+ for(const part of parts) {
2390
+ yield boundaryBytes;
2391
+ yield* part.encode();
2392
+ }
2393
+
2394
+ yield footerBytes;
2395
+ })());
2396
+ };
2397
+
2398
+ const formDataToStream$1 = formDataToStream;
2399
+
2400
+ class ZlibHeaderTransformStream extends stream__default["default"].Transform {
2401
+ __transform(chunk, encoding, callback) {
2402
+ this.push(chunk);
2403
+ callback();
2404
+ }
2405
+
2406
+ _transform(chunk, encoding, callback) {
2407
+ if (chunk.length !== 0) {
2408
+ this._transform = this.__transform;
2409
+
2410
+ // Add Default Compression headers if no zlib headers are present
2411
+ if (chunk[0] !== 120) { // Hex: 78
2412
+ const header = Buffer.alloc(2);
2413
+ header[0] = 120; // Hex: 78
2414
+ header[1] = 156; // Hex: 9C
2415
+ this.push(header, encoding);
2416
+ }
2417
+ }
2418
+
2419
+ this.__transform(chunk, encoding, callback);
1973
2420
  }
1974
2421
  }
1975
2422
 
2423
+ const ZlibHeaderTransformStream$1 = ZlibHeaderTransformStream;
2424
+
2425
+ const zlibOptions = {
2426
+ flush: zlib__default["default"].constants.Z_SYNC_FLUSH,
2427
+ finishFlush: zlib__default["default"].constants.Z_SYNC_FLUSH
2428
+ };
2429
+
2430
+ const brotliOptions = {
2431
+ flush: zlib__default["default"].constants.BROTLI_OPERATION_FLUSH,
2432
+ finishFlush: zlib__default["default"].constants.BROTLI_OPERATION_FLUSH
2433
+ };
2434
+
1976
2435
  const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
1977
2436
 
1978
2437
  const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
@@ -2053,9 +2512,12 @@ function setProxy(options, configProxy, location) {
2053
2512
  };
2054
2513
  }
2055
2514
 
2515
+ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
2516
+
2056
2517
  /*eslint consistent-return:0*/
2057
- function httpAdapter(config) {
2058
- return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
2518
+ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2519
+ /*eslint no-async-promise-executor:0*/
2520
+ return new Promise(async function dispatchHttpRequest(resolvePromise, rejectPromise) {
2059
2521
  let data = config.data;
2060
2522
  const responseType = config.responseType;
2061
2523
  const responseEncoding = config.responseEncoding;
@@ -2119,7 +2581,7 @@ function httpAdapter(config) {
2119
2581
 
2120
2582
  // Parse url
2121
2583
  const fullPath = buildFullPath(config.baseURL, config.url);
2122
- const parsed = new URL(fullPath);
2584
+ const parsed = new URL(fullPath, 'http://localhost');
2123
2585
  const protocol = parsed.protocol || supportedProtocols[0];
2124
2586
 
2125
2587
  if (protocol === 'data:') {
@@ -2146,7 +2608,7 @@ function httpAdapter(config) {
2146
2608
  convertedData = convertedData.toString(responseEncoding);
2147
2609
 
2148
2610
  if (!responseEncoding || responseEncoding === 'utf8') {
2149
- data = utils.stripBOM(convertedData);
2611
+ convertedData = utils.stripBOM(convertedData);
2150
2612
  }
2151
2613
  } else if (responseType === 'stream') {
2152
2614
  convertedData = stream__default["default"].Readable.from(convertedData);
@@ -2156,7 +2618,7 @@ function httpAdapter(config) {
2156
2618
  data: convertedData,
2157
2619
  status: 200,
2158
2620
  statusText: 'OK',
2159
- headers: {},
2621
+ headers: new AxiosHeaders$1(),
2160
2622
  config
2161
2623
  });
2162
2624
  }
@@ -2169,7 +2631,7 @@ function httpAdapter(config) {
2169
2631
  ));
2170
2632
  }
2171
2633
 
2172
- const headers = AxiosHeaders.from(config.headers).normalize();
2634
+ const headers = AxiosHeaders$1.from(config.headers).normalize();
2173
2635
 
2174
2636
  // Set User-Agent (required by some servers)
2175
2637
  // See https://github.com/axios/axios/issues/69
@@ -2183,9 +2645,32 @@ function httpAdapter(config) {
2183
2645
  let maxUploadRate = undefined;
2184
2646
  let maxDownloadRate = undefined;
2185
2647
 
2186
- // support for https://www.npmjs.com/package/form-data api
2187
- if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
2648
+ // support for spec compliant FormData objects
2649
+ if (utils.isSpecCompliantForm(data)) {
2650
+ const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
2651
+
2652
+ data = formDataToStream$1(data, (formHeaders) => {
2653
+ headers.set(formHeaders);
2654
+ }, {
2655
+ tag: `axios-${VERSION}-boundary`,
2656
+ boundary: userBoundary && userBoundary[1] || undefined
2657
+ });
2658
+ // support for https://www.npmjs.com/package/form-data api
2659
+ } else if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
2188
2660
  headers.set(data.getHeaders());
2661
+
2662
+ if (!headers.hasContentLength()) {
2663
+ try {
2664
+ const knownLength = await util__default["default"].promisify(data.getLength).call(data);
2665
+ Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
2666
+ /*eslint no-empty:0*/
2667
+ } catch (e) {
2668
+ }
2669
+ }
2670
+ } else if (utils.isBlob(data)) {
2671
+ data.size && headers.setContentType(data.type || 'application/octet-stream');
2672
+ headers.setContentLength(data.size || 0);
2673
+ data = stream__default["default"].Readable.from(readBlob$1(data));
2189
2674
  } else if (data && !utils.isStream(data)) {
2190
2675
  if (Buffer.isBuffer(data)) ; else if (utils.isArrayBuffer(data)) {
2191
2676
  data = Buffer.from(new Uint8Array(data));
@@ -2200,7 +2685,7 @@ function httpAdapter(config) {
2200
2685
  }
2201
2686
 
2202
2687
  // Add Content-Length header if data exists
2203
- headers.set('Content-Length', data.length, false);
2688
+ headers.setContentLength(data.length, false);
2204
2689
 
2205
2690
  if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
2206
2691
  return reject(new AxiosError(
@@ -2211,7 +2696,7 @@ function httpAdapter(config) {
2211
2696
  }
2212
2697
  }
2213
2698
 
2214
- const contentLength = +headers.getContentLength();
2699
+ const contentLength = utils.toFiniteNumber(headers.getContentLength());
2215
2700
 
2216
2701
  if (utils.isArray(maxRate)) {
2217
2702
  maxUploadRate = maxRate[0];
@@ -2225,8 +2710,8 @@ function httpAdapter(config) {
2225
2710
  data = stream__default["default"].Readable.from(data, {objectMode: false});
2226
2711
  }
2227
2712
 
2228
- data = stream__default["default"].pipeline([data, new AxiosTransformStream({
2229
- length: utils.toFiniteNumber(contentLength),
2713
+ data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
2714
+ length: contentLength,
2230
2715
  maxRate: utils.toFiniteNumber(maxUploadRate)
2231
2716
  })], utils.noop);
2232
2717
 
@@ -2269,7 +2754,10 @@ function httpAdapter(config) {
2269
2754
  return reject(customErr);
2270
2755
  }
2271
2756
 
2272
- headers.set('Accept-Encoding', 'gzip, deflate, br', false);
2757
+ headers.set(
2758
+ 'Accept-Encoding',
2759
+ 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false
2760
+ );
2273
2761
 
2274
2762
  const options = {
2275
2763
  path,
@@ -2324,56 +2812,66 @@ function httpAdapter(config) {
2324
2812
 
2325
2813
  const streams = [res];
2326
2814
 
2327
- // uncompress the response body transparently if required
2815
+ const responseLength = +res.headers['content-length'];
2816
+
2817
+ if (onDownloadProgress) {
2818
+ const transformStream = new AxiosTransformStream$1({
2819
+ length: utils.toFiniteNumber(responseLength),
2820
+ maxRate: utils.toFiniteNumber(maxDownloadRate)
2821
+ });
2822
+
2823
+ onDownloadProgress && transformStream.on('progress', progress => {
2824
+ onDownloadProgress(Object.assign(progress, {
2825
+ download: true
2826
+ }));
2827
+ });
2828
+
2829
+ streams.push(transformStream);
2830
+ }
2831
+
2832
+ // decompress the response body transparently if required
2328
2833
  let responseStream = res;
2329
2834
 
2330
2835
  // return the last request in case of redirects
2331
2836
  const lastRequest = res.req || req;
2332
2837
 
2333
2838
  // if decompress disabled we should not decompress
2334
- if (config.decompress !== false) {
2839
+ if (config.decompress !== false && res.headers['content-encoding']) {
2335
2840
  // if no content, but headers still say that it is encoded,
2336
2841
  // remove the header not confuse downstream operations
2337
- if (data && data.length === 0 && res.headers['content-encoding']) {
2842
+ if (method === 'HEAD' || res.statusCode === 204) {
2338
2843
  delete res.headers['content-encoding'];
2339
2844
  }
2340
2845
 
2341
2846
  switch (res.headers['content-encoding']) {
2342
2847
  /*eslint default-case:0*/
2343
2848
  case 'gzip':
2849
+ case 'x-gzip':
2344
2850
  case 'compress':
2851
+ case 'x-compress':
2852
+ // add the unzipper to the body stream processing pipeline
2853
+ streams.push(zlib__default["default"].createUnzip(zlibOptions));
2854
+
2855
+ // remove the content-encoding in order to not confuse downstream operations
2856
+ delete res.headers['content-encoding'];
2857
+ break;
2345
2858
  case 'deflate':
2859
+ streams.push(new ZlibHeaderTransformStream$1());
2860
+
2346
2861
  // add the unzipper to the body stream processing pipeline
2347
- streams.push(zlib__default["default"].createUnzip());
2862
+ streams.push(zlib__default["default"].createUnzip(zlibOptions));
2348
2863
 
2349
2864
  // remove the content-encoding in order to not confuse downstream operations
2350
2865
  delete res.headers['content-encoding'];
2351
2866
  break;
2352
2867
  case 'br':
2353
2868
  if (isBrotliSupported) {
2354
- streams.push(zlib__default["default"].createBrotliDecompress());
2869
+ streams.push(zlib__default["default"].createBrotliDecompress(brotliOptions));
2355
2870
  delete res.headers['content-encoding'];
2356
2871
  }
2357
2872
  }
2358
2873
  }
2359
2874
 
2360
- if (onDownloadProgress) {
2361
- const responseLength = +res.headers['content-length'];
2362
-
2363
- const transformStream = new AxiosTransformStream({
2364
- length: utils.toFiniteNumber(responseLength),
2365
- maxRate: utils.toFiniteNumber(maxDownloadRate)
2366
- });
2367
-
2368
- onDownloadProgress && transformStream.on('progress', progress => {
2369
- onDownloadProgress(Object.assign(progress, {
2370
- download: true
2371
- }));
2372
- });
2373
-
2374
- streams.push(transformStream);
2375
- }
2376
-
2377
2875
  responseStream = streams.length > 1 ? stream__default["default"].pipeline(streams, utils.noop) : streams[0];
2378
2876
 
2379
2877
  const offListeners = stream__default["default"].finished(responseStream, () => {
@@ -2384,7 +2882,7 @@ function httpAdapter(config) {
2384
2882
  const response = {
2385
2883
  status: res.statusCode,
2386
2884
  statusText: res.statusMessage,
2387
- headers: new AxiosHeaders(res.headers),
2885
+ headers: new AxiosHeaders$1(res.headers),
2388
2886
  config,
2389
2887
  request: lastRequest
2390
2888
  };
@@ -2537,7 +3035,7 @@ function httpAdapter(config) {
2537
3035
  req.end(data);
2538
3036
  }
2539
3037
  });
2540
- }
3038
+ };
2541
3039
 
2542
3040
  const cookies = platform.isStandardBrowserEnv ?
2543
3041
 
@@ -2669,7 +3167,8 @@ function progressEventReducer(listener, isDownloadStream) {
2669
3167
  progress: total ? (loaded / total) : undefined,
2670
3168
  bytes: progressBytes,
2671
3169
  rate: rate ? rate : undefined,
2672
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined
3170
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
3171
+ event: e
2673
3172
  };
2674
3173
 
2675
3174
  data[isDownloadStream ? 'download' : 'upload'] = true;
@@ -2678,10 +3177,12 @@ function progressEventReducer(listener, isDownloadStream) {
2678
3177
  };
2679
3178
  }
2680
3179
 
2681
- function xhrAdapter(config) {
3180
+ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
3181
+
3182
+ const xhrAdapter = isXHRAdapterSupported && function (config) {
2682
3183
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2683
3184
  let requestData = config.data;
2684
- const requestHeaders = AxiosHeaders.from(config.headers).normalize();
3185
+ const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
2685
3186
  const responseType = config.responseType;
2686
3187
  let onCanceled;
2687
3188
  function done() {
@@ -2694,7 +3195,7 @@ function xhrAdapter(config) {
2694
3195
  }
2695
3196
  }
2696
3197
 
2697
- if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
3198
+ if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
2698
3199
  requestHeaders.setContentType(false); // Let the browser set it
2699
3200
  }
2700
3201
 
@@ -2719,10 +3220,10 @@ function xhrAdapter(config) {
2719
3220
  return;
2720
3221
  }
2721
3222
  // Prepare the response
2722
- const responseHeaders = AxiosHeaders.from(
3223
+ const responseHeaders = AxiosHeaders$1.from(
2723
3224
  'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2724
3225
  );
2725
- const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
3226
+ const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
2726
3227
  request.responseText : request.response;
2727
3228
  const response = {
2728
3229
  data: responseData,
@@ -2879,238 +3380,63 @@ function xhrAdapter(config) {
2879
3380
  // Send the request
2880
3381
  request.send(requestData || null);
2881
3382
  });
2882
- }
3383
+ };
2883
3384
 
2884
- const adapters = {
3385
+ const knownAdapters = {
2885
3386
  http: httpAdapter,
2886
3387
  xhr: xhrAdapter
2887
3388
  };
2888
3389
 
2889
- const adapters$1 = {
2890
- getAdapter: (nameOrAdapter) => {
2891
- if(utils.isString(nameOrAdapter)){
2892
- const adapter = adapters[nameOrAdapter];
2893
-
2894
- if (!nameOrAdapter) {
2895
- throw Error(
2896
- utils.hasOwnProp(nameOrAdapter) ?
2897
- `Adapter '${nameOrAdapter}' is not available in the build` :
2898
- `Can not resolve adapter '${nameOrAdapter}'`
2899
- );
2900
- }
2901
-
2902
- return adapter
2903
- }
2904
-
2905
- if (!utils.isFunction(nameOrAdapter)) {
2906
- throw new TypeError('adapter is not a function');
2907
- }
2908
-
2909
- return nameOrAdapter;
2910
- },
2911
- adapters
2912
- };
2913
-
2914
- const DEFAULT_CONTENT_TYPE = {
2915
- 'Content-Type': 'application/x-www-form-urlencoded'
2916
- };
2917
-
2918
- /**
2919
- * If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
2920
- * adapter
2921
- *
2922
- * @returns {Function}
2923
- */
2924
- function getDefaultAdapter() {
2925
- let adapter;
2926
- if (typeof XMLHttpRequest !== 'undefined') {
2927
- // For browsers use XHR adapter
2928
- adapter = adapters$1.getAdapter('xhr');
2929
- } else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
2930
- // For node use HTTP adapter
2931
- adapter = adapters$1.getAdapter('http');
2932
- }
2933
- return adapter;
2934
- }
2935
-
2936
- /**
2937
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
2938
- * of the input
2939
- *
2940
- * @param {any} rawValue - The value to be stringified.
2941
- * @param {Function} parser - A function that parses a string into a JavaScript object.
2942
- * @param {Function} encoder - A function that takes a value and returns a string.
2943
- *
2944
- * @returns {string} A stringified version of the rawValue.
2945
- */
2946
- function stringifySafely(rawValue, parser, encoder) {
2947
- if (utils.isString(rawValue)) {
3390
+ utils.forEach(knownAdapters, (fn, value) => {
3391
+ if(fn) {
2948
3392
  try {
2949
- (parser || JSON.parse)(rawValue);
2950
- return utils.trim(rawValue);
3393
+ Object.defineProperty(fn, 'name', {value});
2951
3394
  } catch (e) {
2952
- if (e.name !== 'SyntaxError') {
2953
- throw e;
2954
- }
3395
+ // eslint-disable-next-line no-empty
2955
3396
  }
3397
+ Object.defineProperty(fn, 'adapterName', {value});
2956
3398
  }
3399
+ });
2957
3400
 
2958
- return (encoder || JSON.stringify)(rawValue);
2959
- }
2960
-
2961
- const defaults = {
2962
-
2963
- transitional: transitionalDefaults,
2964
-
2965
- adapter: getDefaultAdapter(),
2966
-
2967
- transformRequest: [function transformRequest(data, headers) {
2968
- const contentType = headers.getContentType() || '';
2969
- const hasJSONContentType = contentType.indexOf('application/json') > -1;
2970
- const isObjectPayload = utils.isObject(data);
2971
-
2972
- if (isObjectPayload && utils.isHTMLForm(data)) {
2973
- data = new FormData(data);
2974
- }
3401
+ const adapters = {
3402
+ getAdapter: (adapters) => {
3403
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
2975
3404
 
2976
- const isFormData = utils.isFormData(data);
3405
+ const {length} = adapters;
3406
+ let nameOrAdapter;
3407
+ let adapter;
2977
3408
 
2978
- if (isFormData) {
2979
- if (!hasJSONContentType) {
2980
- return data;
3409
+ for (let i = 0; i < length; i++) {
3410
+ nameOrAdapter = adapters[i];
3411
+ if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
3412
+ break;
2981
3413
  }
2982
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
2983
- }
2984
-
2985
- if (utils.isArrayBuffer(data) ||
2986
- utils.isBuffer(data) ||
2987
- utils.isStream(data) ||
2988
- utils.isFile(data) ||
2989
- utils.isBlob(data)
2990
- ) {
2991
- return data;
2992
- }
2993
- if (utils.isArrayBufferView(data)) {
2994
- return data.buffer;
2995
- }
2996
- if (utils.isURLSearchParams(data)) {
2997
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
2998
- return data.toString();
2999
3414
  }
3000
3415
 
3001
- let isFileList;
3002
-
3003
- if (isObjectPayload) {
3004
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
3005
- return toURLEncodedForm(data, this.formSerializer).toString();
3006
- }
3007
-
3008
- if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
3009
- const _FormData = this.env && this.env.FormData;
3010
-
3011
- return toFormData(
3012
- isFileList ? {'files[]': data} : data,
3013
- _FormData && new _FormData(),
3014
- this.formSerializer
3416
+ if (!adapter) {
3417
+ if (adapter === false) {
3418
+ throw new AxiosError(
3419
+ `Adapter ${nameOrAdapter} is not supported by the environment`,
3420
+ 'ERR_NOT_SUPPORT'
3015
3421
  );
3016
3422
  }
3017
- }
3018
3423
 
3019
- if (isObjectPayload || hasJSONContentType ) {
3020
- headers.setContentType('application/json', false);
3021
- return stringifySafely(data);
3424
+ throw new Error(
3425
+ utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
3426
+ `Adapter '${nameOrAdapter}' is not available in the build` :
3427
+ `Unknown adapter '${nameOrAdapter}'`
3428
+ );
3022
3429
  }
3023
3430
 
3024
- return data;
3025
- }],
3026
-
3027
- transformResponse: [function transformResponse(data) {
3028
- const transitional = this.transitional || defaults.transitional;
3029
- const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
3030
- const JSONRequested = this.responseType === 'json';
3031
-
3032
- if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
3033
- const silentJSONParsing = transitional && transitional.silentJSONParsing;
3034
- const strictJSONParsing = !silentJSONParsing && JSONRequested;
3035
-
3036
- try {
3037
- return JSON.parse(data);
3038
- } catch (e) {
3039
- if (strictJSONParsing) {
3040
- if (e.name === 'SyntaxError') {
3041
- throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
3042
- }
3043
- throw e;
3044
- }
3045
- }
3431
+ if (!utils.isFunction(adapter)) {
3432
+ throw new TypeError('adapter is not a function');
3046
3433
  }
3047
3434
 
3048
- return data;
3049
- }],
3050
-
3051
- /**
3052
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
3053
- * timeout is not created.
3054
- */
3055
- timeout: 0,
3056
-
3057
- xsrfCookieName: 'XSRF-TOKEN',
3058
- xsrfHeaderName: 'X-XSRF-TOKEN',
3059
-
3060
- maxContentLength: -1,
3061
- maxBodyLength: -1,
3062
-
3063
- env: {
3064
- FormData: platform.classes.FormData,
3065
- Blob: platform.classes.Blob
3066
- },
3067
-
3068
- validateStatus: function validateStatus(status) {
3069
- return status >= 200 && status < 300;
3435
+ return adapter;
3070
3436
  },
3071
-
3072
- headers: {
3073
- common: {
3074
- 'Accept': 'application/json, text/plain, */*'
3075
- }
3076
- }
3437
+ adapters: knownAdapters
3077
3438
  };
3078
3439
 
3079
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
3080
- defaults.headers[method] = {};
3081
- });
3082
-
3083
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3084
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
3085
- });
3086
-
3087
- /**
3088
- * Transform the data for a request or a response
3089
- *
3090
- * @param {Array|Function} fns A single function or Array of functions
3091
- * @param {?Object} response The response object
3092
- *
3093
- * @returns {*} The resulting transformed data
3094
- */
3095
- function transformData(fns, response) {
3096
- const config = this || defaults;
3097
- const context = response || config;
3098
- const headers = AxiosHeaders.from(context.headers);
3099
- let data = context.data;
3100
-
3101
- utils.forEach(fns, function transform(fn) {
3102
- data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
3103
- });
3104
-
3105
- headers.normalize();
3106
-
3107
- return data;
3108
- }
3109
-
3110
- function isCancel(value) {
3111
- return !!(value && value.__CANCEL__);
3112
- }
3113
-
3114
3440
  /**
3115
3441
  * Throws a `CanceledError` if cancellation has been requested.
3116
3442
  *
@@ -3124,7 +3450,7 @@ function throwIfCancellationRequested(config) {
3124
3450
  }
3125
3451
 
3126
3452
  if (config.signal && config.signal.aborted) {
3127
- throw new CanceledError();
3453
+ throw new CanceledError(null, config);
3128
3454
  }
3129
3455
  }
3130
3456
 
@@ -3138,7 +3464,7 @@ function throwIfCancellationRequested(config) {
3138
3464
  function dispatchRequest(config) {
3139
3465
  throwIfCancellationRequested(config);
3140
3466
 
3141
- config.headers = AxiosHeaders.from(config.headers);
3467
+ config.headers = AxiosHeaders$1.from(config.headers);
3142
3468
 
3143
3469
  // Transform request data
3144
3470
  config.data = transformData.call(
@@ -3146,7 +3472,11 @@ function dispatchRequest(config) {
3146
3472
  config.transformRequest
3147
3473
  );
3148
3474
 
3149
- const adapter = config.adapter || defaults.adapter;
3475
+ if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
3476
+ config.headers.setContentType('application/x-www-form-urlencoded', false);
3477
+ }
3478
+
3479
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3150
3480
 
3151
3481
  return adapter(config).then(function onAdapterResolution(response) {
3152
3482
  throwIfCancellationRequested(config);
@@ -3158,7 +3488,7 @@ function dispatchRequest(config) {
3158
3488
  response
3159
3489
  );
3160
3490
 
3161
- response.headers = AxiosHeaders.from(response.headers);
3491
+ response.headers = AxiosHeaders$1.from(response.headers);
3162
3492
 
3163
3493
  return response;
3164
3494
  }, function onAdapterRejection(reason) {
@@ -3172,7 +3502,7 @@ function dispatchRequest(config) {
3172
3502
  config.transformResponse,
3173
3503
  reason.response
3174
3504
  );
3175
- reason.response.headers = AxiosHeaders.from(reason.response.headers);
3505
+ reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
3176
3506
  }
3177
3507
  }
3178
3508
 
@@ -3180,6 +3510,8 @@ function dispatchRequest(config) {
3180
3510
  });
3181
3511
  }
3182
3512
 
3513
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
3514
+
3183
3515
  /**
3184
3516
  * Config-specific merge-function which creates a new config-object
3185
3517
  * by merging two configuration objects together.
@@ -3194,9 +3526,9 @@ function mergeConfig(config1, config2) {
3194
3526
  config2 = config2 || {};
3195
3527
  const config = {};
3196
3528
 
3197
- function getMergedValue(target, source) {
3529
+ function getMergedValue(target, source, caseless) {
3198
3530
  if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
3199
- return utils.merge(target, source);
3531
+ return utils.merge.call({caseless}, target, source);
3200
3532
  } else if (utils.isPlainObject(source)) {
3201
3533
  return utils.merge({}, source);
3202
3534
  } else if (utils.isArray(source)) {
@@ -3206,72 +3538,73 @@ function mergeConfig(config1, config2) {
3206
3538
  }
3207
3539
 
3208
3540
  // eslint-disable-next-line consistent-return
3209
- function mergeDeepProperties(prop) {
3210
- if (!utils.isUndefined(config2[prop])) {
3211
- return getMergedValue(config1[prop], config2[prop]);
3212
- } else if (!utils.isUndefined(config1[prop])) {
3213
- return getMergedValue(undefined, config1[prop]);
3541
+ function mergeDeepProperties(a, b, caseless) {
3542
+ if (!utils.isUndefined(b)) {
3543
+ return getMergedValue(a, b, caseless);
3544
+ } else if (!utils.isUndefined(a)) {
3545
+ return getMergedValue(undefined, a, caseless);
3214
3546
  }
3215
3547
  }
3216
3548
 
3217
3549
  // eslint-disable-next-line consistent-return
3218
- function valueFromConfig2(prop) {
3219
- if (!utils.isUndefined(config2[prop])) {
3220
- return getMergedValue(undefined, config2[prop]);
3550
+ function valueFromConfig2(a, b) {
3551
+ if (!utils.isUndefined(b)) {
3552
+ return getMergedValue(undefined, b);
3221
3553
  }
3222
3554
  }
3223
3555
 
3224
3556
  // eslint-disable-next-line consistent-return
3225
- function defaultToConfig2(prop) {
3226
- if (!utils.isUndefined(config2[prop])) {
3227
- return getMergedValue(undefined, config2[prop]);
3228
- } else if (!utils.isUndefined(config1[prop])) {
3229
- return getMergedValue(undefined, config1[prop]);
3557
+ function defaultToConfig2(a, b) {
3558
+ if (!utils.isUndefined(b)) {
3559
+ return getMergedValue(undefined, b);
3560
+ } else if (!utils.isUndefined(a)) {
3561
+ return getMergedValue(undefined, a);
3230
3562
  }
3231
3563
  }
3232
3564
 
3233
3565
  // eslint-disable-next-line consistent-return
3234
- function mergeDirectKeys(prop) {
3566
+ function mergeDirectKeys(a, b, prop) {
3235
3567
  if (prop in config2) {
3236
- return getMergedValue(config1[prop], config2[prop]);
3568
+ return getMergedValue(a, b);
3237
3569
  } else if (prop in config1) {
3238
- return getMergedValue(undefined, config1[prop]);
3570
+ return getMergedValue(undefined, a);
3239
3571
  }
3240
3572
  }
3241
3573
 
3242
3574
  const mergeMap = {
3243
- 'url': valueFromConfig2,
3244
- 'method': valueFromConfig2,
3245
- 'data': valueFromConfig2,
3246
- 'baseURL': defaultToConfig2,
3247
- 'transformRequest': defaultToConfig2,
3248
- 'transformResponse': defaultToConfig2,
3249
- 'paramsSerializer': defaultToConfig2,
3250
- 'timeout': defaultToConfig2,
3251
- 'timeoutMessage': defaultToConfig2,
3252
- 'withCredentials': defaultToConfig2,
3253
- 'adapter': defaultToConfig2,
3254
- 'responseType': defaultToConfig2,
3255
- 'xsrfCookieName': defaultToConfig2,
3256
- 'xsrfHeaderName': defaultToConfig2,
3257
- 'onUploadProgress': defaultToConfig2,
3258
- 'onDownloadProgress': defaultToConfig2,
3259
- 'decompress': defaultToConfig2,
3260
- 'maxContentLength': defaultToConfig2,
3261
- 'maxBodyLength': defaultToConfig2,
3262
- 'beforeRedirect': defaultToConfig2,
3263
- 'transport': defaultToConfig2,
3264
- 'httpAgent': defaultToConfig2,
3265
- 'httpsAgent': defaultToConfig2,
3266
- 'cancelToken': defaultToConfig2,
3267
- 'socketPath': defaultToConfig2,
3268
- 'responseEncoding': defaultToConfig2,
3269
- 'validateStatus': mergeDirectKeys
3575
+ url: valueFromConfig2,
3576
+ method: valueFromConfig2,
3577
+ data: valueFromConfig2,
3578
+ baseURL: defaultToConfig2,
3579
+ transformRequest: defaultToConfig2,
3580
+ transformResponse: defaultToConfig2,
3581
+ paramsSerializer: defaultToConfig2,
3582
+ timeout: defaultToConfig2,
3583
+ timeoutMessage: defaultToConfig2,
3584
+ withCredentials: defaultToConfig2,
3585
+ adapter: defaultToConfig2,
3586
+ responseType: defaultToConfig2,
3587
+ xsrfCookieName: defaultToConfig2,
3588
+ xsrfHeaderName: defaultToConfig2,
3589
+ onUploadProgress: defaultToConfig2,
3590
+ onDownloadProgress: defaultToConfig2,
3591
+ decompress: defaultToConfig2,
3592
+ maxContentLength: defaultToConfig2,
3593
+ maxBodyLength: defaultToConfig2,
3594
+ beforeRedirect: defaultToConfig2,
3595
+ transport: defaultToConfig2,
3596
+ httpAgent: defaultToConfig2,
3597
+ httpsAgent: defaultToConfig2,
3598
+ cancelToken: defaultToConfig2,
3599
+ socketPath: defaultToConfig2,
3600
+ responseEncoding: defaultToConfig2,
3601
+ validateStatus: mergeDirectKeys,
3602
+ headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
3270
3603
  };
3271
3604
 
3272
3605
  utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
3273
3606
  const merge = mergeMap[prop] || mergeDeepProperties;
3274
- const configValue = merge(prop);
3607
+ const configValue = merge(config1[prop], config2[prop], prop);
3275
3608
  (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
3276
3609
  });
3277
3610
 
@@ -3378,8 +3711,8 @@ class Axios {
3378
3711
  constructor(instanceConfig) {
3379
3712
  this.defaults = instanceConfig;
3380
3713
  this.interceptors = {
3381
- request: new InterceptorManager(),
3382
- response: new InterceptorManager()
3714
+ request: new InterceptorManager$1(),
3715
+ response: new InterceptorManager$1()
3383
3716
  };
3384
3717
  }
3385
3718
 
@@ -3403,7 +3736,7 @@ class Axios {
3403
3736
 
3404
3737
  config = mergeConfig(this.defaults, config);
3405
3738
 
3406
- const {transitional, paramsSerializer} = config;
3739
+ const {transitional, paramsSerializer, headers} = config;
3407
3740
 
3408
3741
  if (transitional !== undefined) {
3409
3742
  validator.assertOptions(transitional, {
@@ -3423,20 +3756,22 @@ class Axios {
3423
3756
  // Set config.method
3424
3757
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3425
3758
 
3759
+ let contextHeaders;
3760
+
3426
3761
  // Flatten headers
3427
- const defaultHeaders = config.headers && utils.merge(
3428
- config.headers.common,
3429
- config.headers[config.method]
3762
+ contextHeaders = headers && utils.merge(
3763
+ headers.common,
3764
+ headers[config.method]
3430
3765
  );
3431
3766
 
3432
- defaultHeaders && utils.forEach(
3767
+ contextHeaders && utils.forEach(
3433
3768
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3434
- function cleanHeaderConfig(method) {
3435
- delete config.headers[method];
3769
+ (method) => {
3770
+ delete headers[method];
3436
3771
  }
3437
3772
  );
3438
3773
 
3439
- config.headers = new AxiosHeaders(config.headers, defaultHeaders);
3774
+ config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
3440
3775
 
3441
3776
  // filter out skipped interceptors
3442
3777
  const requestInterceptorChain = [];
@@ -3548,6 +3883,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3548
3883
  Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
3549
3884
  });
3550
3885
 
3886
+ const Axios$1 = Axios;
3887
+
3551
3888
  /**
3552
3889
  * A `CancelToken` is an object that can be used to request cancellation of an operation.
3553
3890
  *
@@ -3664,6 +4001,8 @@ class CancelToken {
3664
4001
  }
3665
4002
  }
3666
4003
 
4004
+ const CancelToken$1 = CancelToken;
4005
+
3667
4006
  /**
3668
4007
  * Syntactic sugar for invoking a function and expanding an array for arguments.
3669
4008
  *
@@ -3702,6 +4041,78 @@ function isAxiosError(payload) {
3702
4041
  return utils.isObject(payload) && (payload.isAxiosError === true);
3703
4042
  }
3704
4043
 
4044
+ const HttpStatusCode = {
4045
+ Continue: 100,
4046
+ SwitchingProtocols: 101,
4047
+ Processing: 102,
4048
+ EarlyHints: 103,
4049
+ Ok: 200,
4050
+ Created: 201,
4051
+ Accepted: 202,
4052
+ NonAuthoritativeInformation: 203,
4053
+ NoContent: 204,
4054
+ ResetContent: 205,
4055
+ PartialContent: 206,
4056
+ MultiStatus: 207,
4057
+ AlreadyReported: 208,
4058
+ ImUsed: 226,
4059
+ MultipleChoices: 300,
4060
+ MovedPermanently: 301,
4061
+ Found: 302,
4062
+ SeeOther: 303,
4063
+ NotModified: 304,
4064
+ UseProxy: 305,
4065
+ Unused: 306,
4066
+ TemporaryRedirect: 307,
4067
+ PermanentRedirect: 308,
4068
+ BadRequest: 400,
4069
+ Unauthorized: 401,
4070
+ PaymentRequired: 402,
4071
+ Forbidden: 403,
4072
+ NotFound: 404,
4073
+ MethodNotAllowed: 405,
4074
+ NotAcceptable: 406,
4075
+ ProxyAuthenticationRequired: 407,
4076
+ RequestTimeout: 408,
4077
+ Conflict: 409,
4078
+ Gone: 410,
4079
+ LengthRequired: 411,
4080
+ PreconditionFailed: 412,
4081
+ PayloadTooLarge: 413,
4082
+ UriTooLong: 414,
4083
+ UnsupportedMediaType: 415,
4084
+ RangeNotSatisfiable: 416,
4085
+ ExpectationFailed: 417,
4086
+ ImATeapot: 418,
4087
+ MisdirectedRequest: 421,
4088
+ UnprocessableEntity: 422,
4089
+ Locked: 423,
4090
+ FailedDependency: 424,
4091
+ TooEarly: 425,
4092
+ UpgradeRequired: 426,
4093
+ PreconditionRequired: 428,
4094
+ TooManyRequests: 429,
4095
+ RequestHeaderFieldsTooLarge: 431,
4096
+ UnavailableForLegalReasons: 451,
4097
+ InternalServerError: 500,
4098
+ NotImplemented: 501,
4099
+ BadGateway: 502,
4100
+ ServiceUnavailable: 503,
4101
+ GatewayTimeout: 504,
4102
+ HttpVersionNotSupported: 505,
4103
+ VariantAlsoNegotiates: 506,
4104
+ InsufficientStorage: 507,
4105
+ LoopDetected: 508,
4106
+ NotExtended: 510,
4107
+ NetworkAuthenticationRequired: 511,
4108
+ };
4109
+
4110
+ Object.entries(HttpStatusCode).forEach(([key, value]) => {
4111
+ HttpStatusCode[value] = key;
4112
+ });
4113
+
4114
+ const HttpStatusCode$1 = HttpStatusCode;
4115
+
3705
4116
  /**
3706
4117
  * Create an instance of Axios
3707
4118
  *
@@ -3710,11 +4121,11 @@ function isAxiosError(payload) {
3710
4121
  * @returns {Axios} A new instance of Axios
3711
4122
  */
3712
4123
  function createInstance(defaultConfig) {
3713
- const context = new Axios(defaultConfig);
3714
- const instance = bind(Axios.prototype.request, context);
4124
+ const context = new Axios$1(defaultConfig);
4125
+ const instance = bind(Axios$1.prototype.request, context);
3715
4126
 
3716
4127
  // Copy axios.prototype to instance
3717
- utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
4128
+ utils.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
3718
4129
 
3719
4130
  // Copy context to instance
3720
4131
  utils.extend(instance, context, null, {allOwnKeys: true});
@@ -3728,14 +4139,14 @@ function createInstance(defaultConfig) {
3728
4139
  }
3729
4140
 
3730
4141
  // Create the default instance to be exported
3731
- const axios = createInstance(defaults);
4142
+ const axios = createInstance(defaults$1);
3732
4143
 
3733
4144
  // Expose Axios class to allow class inheritance
3734
- axios.Axios = Axios;
4145
+ axios.Axios = Axios$1;
3735
4146
 
3736
4147
  // Expose Cancel & CancelToken
3737
4148
  axios.CanceledError = CanceledError;
3738
- axios.CancelToken = CancelToken;
4149
+ axios.CancelToken = CancelToken$1;
3739
4150
  axios.isCancel = isCancel;
3740
4151
  axios.VERSION = VERSION;
3741
4152
  axios.toFormData = toFormData;
@@ -3756,9 +4167,16 @@ axios.spread = spread;
3756
4167
  // Expose isAxiosError
3757
4168
  axios.isAxiosError = isAxiosError;
3758
4169
 
3759
- axios.formToJSON = thing => {
3760
- return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3761
- };
4170
+ // Expose mergeConfig
4171
+ axios.mergeConfig = mergeConfig;
4172
+
4173
+ axios.AxiosHeaders = AxiosHeaders$1;
4174
+
4175
+ axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
4176
+
4177
+ axios.HttpStatusCode = HttpStatusCode$1;
4178
+
4179
+ axios.default = axios;
3762
4180
 
3763
4181
  module.exports = axios;
3764
4182
  //# sourceMappingURL=axios.cjs.map