axios 1.1.2 → 1.2.0-alpha.1

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

Potentially problematic release.


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

@@ -1,4 +1,4 @@
1
- // Axios v1.1.2 Copyright (c) 2022 Matt Zabriskie and contributors
1
+ // Axios v1.2.0-alpha.1 Copyright (c) 2022 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -254,7 +254,7 @@ const trim = (str) => str.trim ?
254
254
  * @param {Function} fn The callback to invoke for each item
255
255
  *
256
256
  * @param {Boolean} [allOwnKeys = false]
257
- * @returns {void}
257
+ * @returns {any}
258
258
  */
259
259
  function forEach(obj, fn, {allOwnKeys = false} = {}) {
260
260
  // Don't bother if no value provided
@@ -289,6 +289,24 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
289
289
  }
290
290
  }
291
291
 
292
+ function findKey(obj, key) {
293
+ key = key.toLowerCase();
294
+ const keys = Object.keys(obj);
295
+ let i = keys.length;
296
+ let _key;
297
+ while (i-- > 0) {
298
+ _key = keys[i];
299
+ if (key === _key.toLowerCase()) {
300
+ return _key;
301
+ }
302
+ }
303
+ return null;
304
+ }
305
+
306
+ const _global = typeof self === "undefined" ? typeof global === "undefined" ? undefined : global : self;
307
+
308
+ const isContextDefined = (context) => !isUndefined(context) && context !== _global;
309
+
292
310
  /**
293
311
  * Accepts varargs expecting each argument to be an object, then
294
312
  * immutably merges the properties of each object and returns result.
@@ -308,16 +326,18 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
308
326
  * @returns {Object} Result of all merge properties
309
327
  */
310
328
  function merge(/* obj1, obj2, obj3, ... */) {
329
+ const {caseless} = isContextDefined(this) && this || {};
311
330
  const result = {};
312
331
  const assignValue = (val, key) => {
313
- if (isPlainObject(result[key]) && isPlainObject(val)) {
314
- result[key] = merge(result[key], val);
332
+ const targetKey = caseless && findKey(result, key) || key;
333
+ if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
334
+ result[targetKey] = merge(result[targetKey], val);
315
335
  } else if (isPlainObject(val)) {
316
- result[key] = merge({}, val);
336
+ result[targetKey] = merge({}, val);
317
337
  } else if (isArray(val)) {
318
- result[key] = val.slice();
338
+ result[targetKey] = val.slice();
319
339
  } else {
320
- result[key] = val;
340
+ result[targetKey] = val;
321
341
  }
322
342
  };
323
343
 
@@ -553,6 +573,11 @@ const reduceDescriptors = (obj, reducer) => {
553
573
 
554
574
  const freezeMethods = (obj) => {
555
575
  reduceDescriptors(obj, (descriptor, name) => {
576
+ // skip restricted props in strict mode
577
+ if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
578
+ return false;
579
+ }
580
+
556
581
  const value = obj[name];
557
582
 
558
583
  if (!isFunction(value)) return;
@@ -566,7 +591,7 @@ const freezeMethods = (obj) => {
566
591
 
567
592
  if (!descriptor.set) {
568
593
  descriptor.set = () => {
569
- throw Error('Can not read-only method \'' + name + '\'');
594
+ throw Error('Can not rewrite read-only method \'' + name + '\'');
570
595
  };
571
596
  }
572
597
  });
@@ -635,7 +660,10 @@ const utils = {
635
660
  toObjectSet,
636
661
  toCamelCase,
637
662
  noop,
638
- toFiniteNumber
663
+ toFiniteNumber,
664
+ findKey,
665
+ global: _global,
666
+ isContextDefined
639
667
  };
640
668
 
641
669
  /**
@@ -897,7 +925,7 @@ function toFormData(obj, formData, options) {
897
925
  key = removeBrackets(key);
898
926
 
899
927
  arr.forEach(function each(el, index) {
900
- !utils.isUndefined(el) && formData.append(
928
+ !(utils.isUndefined(el) || el === null) && formData.append(
901
929
  // eslint-disable-next-line no-nested-ternary
902
930
  indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
903
931
  convertValue(el)
@@ -934,7 +962,7 @@ function toFormData(obj, formData, options) {
934
962
  stack.push(value);
935
963
 
936
964
  utils.forEach(value, function each(el, key) {
937
- const result = !utils.isUndefined(el) && visitor.call(
965
+ const result = !(utils.isUndefined(el) || el === null) && visitor.call(
938
966
  formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
939
967
  );
940
968
 
@@ -1040,21 +1068,28 @@ function buildURL(url, params, options) {
1040
1068
  if (!params) {
1041
1069
  return url;
1042
1070
  }
1071
+
1072
+ const _encode = options && options.encode || encode;
1043
1073
 
1044
- const hashmarkIndex = url.indexOf('#');
1074
+ const serializeFn = options && options.serialize;
1045
1075
 
1046
- if (hashmarkIndex !== -1) {
1047
- url = url.slice(0, hashmarkIndex);
1048
- }
1076
+ let serializedParams;
1049
1077
 
1050
- const _encode = options && options.encode || encode;
1078
+ if (serializeFn) {
1079
+ serializedParams = serializeFn(params, options);
1080
+ } else {
1081
+ serializedParams = utils.isURLSearchParams(params) ?
1082
+ params.toString() :
1083
+ new AxiosURLSearchParams(params, options).toString(_encode);
1084
+ }
1051
1085
 
1052
- const serializerParams = utils.isURLSearchParams(params) ?
1053
- params.toString() :
1054
- new AxiosURLSearchParams(params, options).toString(_encode);
1086
+ if (serializedParams) {
1087
+ const hashmarkIndex = url.indexOf("#");
1055
1088
 
1056
- if (serializerParams) {
1057
- url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams;
1089
+ if (hashmarkIndex !== -1) {
1090
+ url = url.slice(0, hashmarkIndex);
1091
+ }
1092
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
1058
1093
  }
1059
1094
 
1060
1095
  return url;
@@ -1126,6 +1161,8 @@ class InterceptorManager {
1126
1161
  }
1127
1162
  }
1128
1163
 
1164
+ const InterceptorManager$1 = InterceptorManager;
1165
+
1129
1166
  const transitionalDefaults = {
1130
1167
  silentJSONParsing: true,
1131
1168
  forcedJSONParsing: true,
@@ -1313,7 +1350,7 @@ function buildFullPath(baseURL, requestedURL) {
1313
1350
  return requestedURL;
1314
1351
  }
1315
1352
 
1316
- const VERSION = "1.1.2";
1353
+ const VERSION = "1.2.0-alpha.1";
1317
1354
 
1318
1355
  /**
1319
1356
  * A `CanceledError` is an object that is thrown when an operation is canceled.
@@ -1440,7 +1477,6 @@ const parseHeaders = rawHeaders => {
1440
1477
  };
1441
1478
 
1442
1479
  const $internals = Symbol('internals');
1443
- const $defaults = Symbol('defaults');
1444
1480
 
1445
1481
  function normalizeHeader(header) {
1446
1482
  return header && String(header).trim().toLowerCase();
@@ -1451,7 +1487,7 @@ function normalizeValue(value) {
1451
1487
  return value;
1452
1488
  }
1453
1489
 
1454
- return String(value);
1490
+ return utils.isArray(value) ? value.map(normalizeValue) : String(value);
1455
1491
  }
1456
1492
 
1457
1493
  function parseTokens(str) {
@@ -1466,6 +1502,10 @@ function parseTokens(str) {
1466
1502
  return tokens;
1467
1503
  }
1468
1504
 
1505
+ function isValidHeaderName(str) {
1506
+ return /^[-_a-zA-Z]+$/.test(str.trim());
1507
+ }
1508
+
1469
1509
  function matchHeaderValue(context, value, header, filter) {
1470
1510
  if (utils.isFunction(filter)) {
1471
1511
  return filter.call(this, value, header);
@@ -1502,27 +1542,12 @@ function buildAccessors(obj, header) {
1502
1542
  });
1503
1543
  }
1504
1544
 
1505
- function findKey(obj, key) {
1506
- key = key.toLowerCase();
1507
- const keys = Object.keys(obj);
1508
- let i = keys.length;
1509
- let _key;
1510
- while (i-- > 0) {
1511
- _key = keys[i];
1512
- if (key === _key.toLowerCase()) {
1513
- return _key;
1514
- }
1545
+ class AxiosHeaders {
1546
+ constructor(headers) {
1547
+ headers && this.set(headers);
1515
1548
  }
1516
- return null;
1517
- }
1518
1549
 
1519
- function AxiosHeaders(headers, defaults) {
1520
- headers && this.set(headers);
1521
- this[$defaults] = defaults || null;
1522
- }
1523
-
1524
- Object.assign(AxiosHeaders.prototype, {
1525
- set: function(header, valueOrRewrite, rewrite) {
1550
+ set(header, valueOrRewrite, rewrite) {
1526
1551
  const self = this;
1527
1552
 
1528
1553
  function setHeader(_value, _header, _rewrite) {
@@ -1532,75 +1557,70 @@ Object.assign(AxiosHeaders.prototype, {
1532
1557
  throw new Error('header name must be a non-empty string');
1533
1558
  }
1534
1559
 
1535
- const key = findKey(self, lHeader);
1560
+ const key = utils.findKey(self, lHeader);
1536
1561
 
1537
- if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
1538
- return;
1562
+ if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
1563
+ self[key || _header] = normalizeValue(_value);
1539
1564
  }
1540
-
1541
- if (utils.isArray(_value)) {
1542
- _value = _value.map(normalizeValue);
1543
- } else {
1544
- _value = normalizeValue(_value);
1545
- }
1546
-
1547
- self[key || _header] = _value;
1548
1565
  }
1549
1566
 
1550
- if (utils.isPlainObject(header)) {
1551
- utils.forEach(header, (_value, _header) => {
1552
- setHeader(_value, _header, valueOrRewrite);
1553
- });
1567
+ const setHeaders = (headers, _rewrite) =>
1568
+ utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
1569
+
1570
+ if (utils.isPlainObject(header) || header instanceof this.constructor) {
1571
+ setHeaders(header, valueOrRewrite);
1572
+ } else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1573
+ setHeaders(parseHeaders(header), valueOrRewrite);
1554
1574
  } else {
1555
- setHeader(valueOrRewrite, header, rewrite);
1575
+ header != null && setHeader(valueOrRewrite, header, rewrite);
1556
1576
  }
1557
1577
 
1558
1578
  return this;
1559
- },
1579
+ }
1560
1580
 
1561
- get: function(header, parser) {
1581
+ get(header, parser) {
1562
1582
  header = normalizeHeader(header);
1563
1583
 
1564
- if (!header) return undefined;
1584
+ if (header) {
1585
+ const key = utils.findKey(this, header);
1565
1586
 
1566
- const key = findKey(this, header);
1587
+ if (key) {
1588
+ const value = this[key];
1567
1589
 
1568
- if (key) {
1569
- const value = this[key];
1590
+ if (!parser) {
1591
+ return value;
1592
+ }
1570
1593
 
1571
- if (!parser) {
1572
- return value;
1573
- }
1594
+ if (parser === true) {
1595
+ return parseTokens(value);
1596
+ }
1574
1597
 
1575
- if (parser === true) {
1576
- return parseTokens(value);
1577
- }
1598
+ if (utils.isFunction(parser)) {
1599
+ return parser.call(this, value, key);
1600
+ }
1578
1601
 
1579
- if (utils.isFunction(parser)) {
1580
- return parser.call(this, value, key);
1581
- }
1602
+ if (utils.isRegExp(parser)) {
1603
+ return parser.exec(value);
1604
+ }
1582
1605
 
1583
- if (utils.isRegExp(parser)) {
1584
- return parser.exec(value);
1606
+ throw new TypeError('parser must be boolean|regexp|function');
1585
1607
  }
1586
-
1587
- throw new TypeError('parser must be boolean|regexp|function');
1588
1608
  }
1589
- },
1609
+ }
1590
1610
 
1591
- has: function(header, matcher) {
1611
+ has(header, matcher) {
1592
1612
  header = normalizeHeader(header);
1593
1613
 
1594
1614
  if (header) {
1595
- const key = findKey(this, header);
1615
+ const key = utils.findKey(this, header);
1596
1616
 
1597
1617
  return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1598
1618
  }
1599
1619
 
1600
1620
  return false;
1601
- },
1621
+ }
1602
1622
 
1603
- delete: function(header, matcher) {
1623
+ delete(header, matcher) {
1604
1624
  const self = this;
1605
1625
  let deleted = false;
1606
1626
 
@@ -1608,7 +1628,7 @@ Object.assign(AxiosHeaders.prototype, {
1608
1628
  _header = normalizeHeader(_header);
1609
1629
 
1610
1630
  if (_header) {
1611
- const key = findKey(self, _header);
1631
+ const key = utils.findKey(self, _header);
1612
1632
 
1613
1633
  if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1614
1634
  delete self[key];
@@ -1625,18 +1645,18 @@ Object.assign(AxiosHeaders.prototype, {
1625
1645
  }
1626
1646
 
1627
1647
  return deleted;
1628
- },
1648
+ }
1629
1649
 
1630
- clear: function() {
1650
+ clear() {
1631
1651
  return Object.keys(this).forEach(this.delete.bind(this));
1632
- },
1652
+ }
1633
1653
 
1634
- normalize: function(format) {
1654
+ normalize(format) {
1635
1655
  const self = this;
1636
1656
  const headers = {};
1637
1657
 
1638
1658
  utils.forEach(this, (value, header) => {
1639
- const key = findKey(headers, header);
1659
+ const key = utils.findKey(headers, header);
1640
1660
 
1641
1661
  if (key) {
1642
1662
  self[key] = normalizeValue(value);
@@ -1656,30 +1676,47 @@ Object.assign(AxiosHeaders.prototype, {
1656
1676
  });
1657
1677
 
1658
1678
  return this;
1659
- },
1679
+ }
1660
1680
 
1661
- toJSON: function() {
1681
+ concat(...targets) {
1682
+ return this.constructor.concat(this, ...targets);
1683
+ }
1684
+
1685
+ toJSON(asStrings) {
1662
1686
  const obj = Object.create(null);
1663
1687
 
1664
- utils.forEach(Object.assign({}, this[$defaults] || null, this),
1665
- (value, header) => {
1666
- if (value == null || value === false) return;
1667
- obj[header] = utils.isArray(value) ? value.join(', ') : value;
1668
- });
1688
+ utils.forEach(this, (value, header) => {
1689
+ value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
1690
+ });
1669
1691
 
1670
1692
  return obj;
1671
1693
  }
1672
- });
1673
1694
 
1674
- Object.assign(AxiosHeaders, {
1675
- from: function(thing) {
1676
- if (utils.isString(thing)) {
1677
- return new this(parseHeaders(thing));
1678
- }
1695
+ [Symbol.iterator]() {
1696
+ return Object.entries(this.toJSON())[Symbol.iterator]();
1697
+ }
1698
+
1699
+ toString() {
1700
+ return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
1701
+ }
1702
+
1703
+ get [Symbol.toStringTag]() {
1704
+ return 'AxiosHeaders';
1705
+ }
1706
+
1707
+ static from(thing) {
1679
1708
  return thing instanceof this ? thing : new this(thing);
1680
- },
1709
+ }
1710
+
1711
+ static concat(first, ...targets) {
1712
+ const computed = new this(first);
1681
1713
 
1682
- accessor: function(header) {
1714
+ targets.forEach((target) => computed.set(target));
1715
+
1716
+ return computed;
1717
+ }
1718
+
1719
+ static accessor(header) {
1683
1720
  const internals = this[$internals] = (this[$internals] = {
1684
1721
  accessors: {}
1685
1722
  });
@@ -1700,13 +1737,15 @@ Object.assign(AxiosHeaders, {
1700
1737
 
1701
1738
  return this;
1702
1739
  }
1703
- });
1740
+ }
1704
1741
 
1705
1742
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1706
1743
 
1707
1744
  utils.freezeMethods(AxiosHeaders.prototype);
1708
1745
  utils.freezeMethods(AxiosHeaders);
1709
1746
 
1747
+ const AxiosHeaders$1 = AxiosHeaders;
1748
+
1710
1749
  /**
1711
1750
  * Throttle decorator
1712
1751
  * @param {Function} fn
@@ -1972,6 +2011,8 @@ class AxiosTransformStream extends stream__default["default"].Transform{
1972
2011
  }
1973
2012
  }
1974
2013
 
2014
+ const AxiosTransformStream$1 = AxiosTransformStream;
2015
+
1975
2016
  const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
1976
2017
 
1977
2018
  const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
@@ -2003,7 +2044,7 @@ function dispatchBeforeRedirect(options) {
2003
2044
  * If the proxy or config afterRedirects functions are defined, call them with the options
2004
2045
  *
2005
2046
  * @param {http.ClientRequestArgs} options
2006
- * @param {AxiosProxyConfig} configProxy
2047
+ * @param {AxiosProxyConfig} configProxy configuration from Axios options object
2007
2048
  * @param {string} location
2008
2049
  *
2009
2050
  * @returns {http.ClientRequestArgs}
@@ -2034,13 +2075,14 @@ function setProxy(options, configProxy, location) {
2034
2075
  }
2035
2076
 
2036
2077
  options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
2037
- options.hostname = proxy.hostname;
2078
+ const proxyHost = proxy.hostname || proxy.host;
2079
+ options.hostname = proxyHost;
2038
2080
  // Replace 'host' since options is not a URL object
2039
- options.host = proxy.hostname;
2081
+ options.host = proxyHost;
2040
2082
  options.port = proxy.port;
2041
2083
  options.path = location;
2042
2084
  if (proxy.protocol) {
2043
- options.protocol = proxy.protocol;
2085
+ options.protocol = proxy.protocol.includes(':') ? proxy.protocol : `${proxy.protocol}:`;
2044
2086
  }
2045
2087
  }
2046
2088
 
@@ -2154,7 +2196,7 @@ function httpAdapter(config) {
2154
2196
  data: convertedData,
2155
2197
  status: 200,
2156
2198
  statusText: 'OK',
2157
- headers: {},
2199
+ headers: new AxiosHeaders$1(),
2158
2200
  config
2159
2201
  });
2160
2202
  }
@@ -2167,7 +2209,7 @@ function httpAdapter(config) {
2167
2209
  ));
2168
2210
  }
2169
2211
 
2170
- const headers = AxiosHeaders.from(config.headers).normalize();
2212
+ const headers = AxiosHeaders$1.from(config.headers).normalize();
2171
2213
 
2172
2214
  // Set User-Agent (required by some servers)
2173
2215
  // See https://github.com/axios/axios/issues/69
@@ -2223,7 +2265,7 @@ function httpAdapter(config) {
2223
2265
  data = stream__default["default"].Readable.from(data, {objectMode: false});
2224
2266
  }
2225
2267
 
2226
- data = stream__default["default"].pipeline([data, new AxiosTransformStream({
2268
+ data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
2227
2269
  length: utils.toFiniteNumber(contentLength),
2228
2270
  maxRate: utils.toFiniteNumber(maxUploadRate)
2229
2271
  })], utils.noop);
@@ -2358,7 +2400,7 @@ function httpAdapter(config) {
2358
2400
  if (onDownloadProgress) {
2359
2401
  const responseLength = +res.headers['content-length'];
2360
2402
 
2361
- const transformStream = new AxiosTransformStream({
2403
+ const transformStream = new AxiosTransformStream$1({
2362
2404
  length: utils.toFiniteNumber(responseLength),
2363
2405
  maxRate: utils.toFiniteNumber(maxDownloadRate)
2364
2406
  });
@@ -2382,7 +2424,7 @@ function httpAdapter(config) {
2382
2424
  const response = {
2383
2425
  status: res.statusCode,
2384
2426
  statusText: res.statusMessage,
2385
- headers: new AxiosHeaders(res.headers),
2427
+ headers: new AxiosHeaders$1(res.headers),
2386
2428
  config,
2387
2429
  request: lastRequest
2388
2430
  };
@@ -2667,7 +2709,8 @@ function progressEventReducer(listener, isDownloadStream) {
2667
2709
  progress: total ? (loaded / total) : undefined,
2668
2710
  bytes: progressBytes,
2669
2711
  rate: rate ? rate : undefined,
2670
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined
2712
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2713
+ event: e
2671
2714
  };
2672
2715
 
2673
2716
  data[isDownloadStream ? 'download' : 'upload'] = true;
@@ -2679,7 +2722,7 @@ function progressEventReducer(listener, isDownloadStream) {
2679
2722
  function xhrAdapter(config) {
2680
2723
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2681
2724
  let requestData = config.data;
2682
- const requestHeaders = AxiosHeaders.from(config.headers).normalize();
2725
+ const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
2683
2726
  const responseType = config.responseType;
2684
2727
  let onCanceled;
2685
2728
  function done() {
@@ -2717,7 +2760,7 @@ function xhrAdapter(config) {
2717
2760
  return;
2718
2761
  }
2719
2762
  // Prepare the response
2720
- const responseHeaders = AxiosHeaders.from(
2763
+ const responseHeaders = AxiosHeaders$1.from(
2721
2764
  'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2722
2765
  );
2723
2766
  const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
@@ -2910,7 +2953,7 @@ const adapters$1 = {
2910
2953
  };
2911
2954
 
2912
2955
  const DEFAULT_CONTENT_TYPE = {
2913
- 'Content-Type': 'application/x-www-form-urlencoded'
2956
+ 'Content-Type': undefined
2914
2957
  };
2915
2958
 
2916
2959
  /**
@@ -3082,6 +3125,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3082
3125
  defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
3083
3126
  });
3084
3127
 
3128
+ const defaults$1 = defaults;
3129
+
3085
3130
  /**
3086
3131
  * Transform the data for a request or a response
3087
3132
  *
@@ -3091,9 +3136,9 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3091
3136
  * @returns {*} The resulting transformed data
3092
3137
  */
3093
3138
  function transformData(fns, response) {
3094
- const config = this || defaults;
3139
+ const config = this || defaults$1;
3095
3140
  const context = response || config;
3096
- const headers = AxiosHeaders.from(context.headers);
3141
+ const headers = AxiosHeaders$1.from(context.headers);
3097
3142
  let data = context.data;
3098
3143
 
3099
3144
  utils.forEach(fns, function transform(fn) {
@@ -3136,7 +3181,7 @@ function throwIfCancellationRequested(config) {
3136
3181
  function dispatchRequest(config) {
3137
3182
  throwIfCancellationRequested(config);
3138
3183
 
3139
- config.headers = AxiosHeaders.from(config.headers);
3184
+ config.headers = AxiosHeaders$1.from(config.headers);
3140
3185
 
3141
3186
  // Transform request data
3142
3187
  config.data = transformData.call(
@@ -3144,7 +3189,11 @@ function dispatchRequest(config) {
3144
3189
  config.transformRequest
3145
3190
  );
3146
3191
 
3147
- const adapter = config.adapter || defaults.adapter;
3192
+ if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
3193
+ config.headers.setContentType('application/x-www-form-urlencoded', false);
3194
+ }
3195
+
3196
+ const adapter = config.adapter || defaults$1.adapter;
3148
3197
 
3149
3198
  return adapter(config).then(function onAdapterResolution(response) {
3150
3199
  throwIfCancellationRequested(config);
@@ -3156,7 +3205,7 @@ function dispatchRequest(config) {
3156
3205
  response
3157
3206
  );
3158
3207
 
3159
- response.headers = AxiosHeaders.from(response.headers);
3208
+ response.headers = AxiosHeaders$1.from(response.headers);
3160
3209
 
3161
3210
  return response;
3162
3211
  }, function onAdapterRejection(reason) {
@@ -3170,7 +3219,7 @@ function dispatchRequest(config) {
3170
3219
  config.transformResponse,
3171
3220
  reason.response
3172
3221
  );
3173
- reason.response.headers = AxiosHeaders.from(reason.response.headers);
3222
+ reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
3174
3223
  }
3175
3224
  }
3176
3225
 
@@ -3178,6 +3227,8 @@ function dispatchRequest(config) {
3178
3227
  });
3179
3228
  }
3180
3229
 
3230
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
3231
+
3181
3232
  /**
3182
3233
  * Config-specific merge-function which creates a new config-object
3183
3234
  * by merging two configuration objects together.
@@ -3192,9 +3243,9 @@ function mergeConfig(config1, config2) {
3192
3243
  config2 = config2 || {};
3193
3244
  const config = {};
3194
3245
 
3195
- function getMergedValue(target, source) {
3246
+ function getMergedValue(target, source, caseless) {
3196
3247
  if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
3197
- return utils.merge(target, source);
3248
+ return utils.merge.call({caseless}, target, source);
3198
3249
  } else if (utils.isPlainObject(source)) {
3199
3250
  return utils.merge({}, source);
3200
3251
  } else if (utils.isArray(source)) {
@@ -3204,72 +3255,73 @@ function mergeConfig(config1, config2) {
3204
3255
  }
3205
3256
 
3206
3257
  // eslint-disable-next-line consistent-return
3207
- function mergeDeepProperties(prop) {
3208
- if (!utils.isUndefined(config2[prop])) {
3209
- return getMergedValue(config1[prop], config2[prop]);
3210
- } else if (!utils.isUndefined(config1[prop])) {
3211
- return getMergedValue(undefined, config1[prop]);
3258
+ function mergeDeepProperties(a, b, caseless) {
3259
+ if (!utils.isUndefined(b)) {
3260
+ return getMergedValue(a, b, caseless);
3261
+ } else if (!utils.isUndefined(a)) {
3262
+ return getMergedValue(undefined, a, caseless);
3212
3263
  }
3213
3264
  }
3214
3265
 
3215
3266
  // eslint-disable-next-line consistent-return
3216
- function valueFromConfig2(prop) {
3217
- if (!utils.isUndefined(config2[prop])) {
3218
- return getMergedValue(undefined, config2[prop]);
3267
+ function valueFromConfig2(a, b) {
3268
+ if (!utils.isUndefined(b)) {
3269
+ return getMergedValue(undefined, b);
3219
3270
  }
3220
3271
  }
3221
3272
 
3222
3273
  // eslint-disable-next-line consistent-return
3223
- function defaultToConfig2(prop) {
3224
- if (!utils.isUndefined(config2[prop])) {
3225
- return getMergedValue(undefined, config2[prop]);
3226
- } else if (!utils.isUndefined(config1[prop])) {
3227
- return getMergedValue(undefined, config1[prop]);
3274
+ function defaultToConfig2(a, b) {
3275
+ if (!utils.isUndefined(b)) {
3276
+ return getMergedValue(undefined, b);
3277
+ } else if (!utils.isUndefined(a)) {
3278
+ return getMergedValue(undefined, a);
3228
3279
  }
3229
3280
  }
3230
3281
 
3231
3282
  // eslint-disable-next-line consistent-return
3232
- function mergeDirectKeys(prop) {
3283
+ function mergeDirectKeys(a, b, prop) {
3233
3284
  if (prop in config2) {
3234
- return getMergedValue(config1[prop], config2[prop]);
3285
+ return getMergedValue(a, b);
3235
3286
  } else if (prop in config1) {
3236
- return getMergedValue(undefined, config1[prop]);
3287
+ return getMergedValue(undefined, a);
3237
3288
  }
3238
3289
  }
3239
3290
 
3240
3291
  const mergeMap = {
3241
- 'url': valueFromConfig2,
3242
- 'method': valueFromConfig2,
3243
- 'data': valueFromConfig2,
3244
- 'baseURL': defaultToConfig2,
3245
- 'transformRequest': defaultToConfig2,
3246
- 'transformResponse': defaultToConfig2,
3247
- 'paramsSerializer': defaultToConfig2,
3248
- 'timeout': defaultToConfig2,
3249
- 'timeoutMessage': defaultToConfig2,
3250
- 'withCredentials': defaultToConfig2,
3251
- 'adapter': defaultToConfig2,
3252
- 'responseType': defaultToConfig2,
3253
- 'xsrfCookieName': defaultToConfig2,
3254
- 'xsrfHeaderName': defaultToConfig2,
3255
- 'onUploadProgress': defaultToConfig2,
3256
- 'onDownloadProgress': defaultToConfig2,
3257
- 'decompress': defaultToConfig2,
3258
- 'maxContentLength': defaultToConfig2,
3259
- 'maxBodyLength': defaultToConfig2,
3260
- 'beforeRedirect': defaultToConfig2,
3261
- 'transport': defaultToConfig2,
3262
- 'httpAgent': defaultToConfig2,
3263
- 'httpsAgent': defaultToConfig2,
3264
- 'cancelToken': defaultToConfig2,
3265
- 'socketPath': defaultToConfig2,
3266
- 'responseEncoding': defaultToConfig2,
3267
- 'validateStatus': mergeDirectKeys
3292
+ url: valueFromConfig2,
3293
+ method: valueFromConfig2,
3294
+ data: valueFromConfig2,
3295
+ baseURL: defaultToConfig2,
3296
+ transformRequest: defaultToConfig2,
3297
+ transformResponse: defaultToConfig2,
3298
+ paramsSerializer: defaultToConfig2,
3299
+ timeout: defaultToConfig2,
3300
+ timeoutMessage: defaultToConfig2,
3301
+ withCredentials: defaultToConfig2,
3302
+ adapter: defaultToConfig2,
3303
+ responseType: defaultToConfig2,
3304
+ xsrfCookieName: defaultToConfig2,
3305
+ xsrfHeaderName: defaultToConfig2,
3306
+ onUploadProgress: defaultToConfig2,
3307
+ onDownloadProgress: defaultToConfig2,
3308
+ decompress: defaultToConfig2,
3309
+ maxContentLength: defaultToConfig2,
3310
+ maxBodyLength: defaultToConfig2,
3311
+ beforeRedirect: defaultToConfig2,
3312
+ transport: defaultToConfig2,
3313
+ httpAgent: defaultToConfig2,
3314
+ httpsAgent: defaultToConfig2,
3315
+ cancelToken: defaultToConfig2,
3316
+ socketPath: defaultToConfig2,
3317
+ responseEncoding: defaultToConfig2,
3318
+ validateStatus: mergeDirectKeys,
3319
+ headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
3268
3320
  };
3269
3321
 
3270
3322
  utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
3271
3323
  const merge = mergeMap[prop] || mergeDeepProperties;
3272
- const configValue = merge(prop);
3324
+ const configValue = merge(config1[prop], config2[prop], prop);
3273
3325
  (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
3274
3326
  });
3275
3327
 
@@ -3376,8 +3428,8 @@ class Axios {
3376
3428
  constructor(instanceConfig) {
3377
3429
  this.defaults = instanceConfig;
3378
3430
  this.interceptors = {
3379
- request: new InterceptorManager(),
3380
- response: new InterceptorManager()
3431
+ request: new InterceptorManager$1(),
3432
+ response: new InterceptorManager$1()
3381
3433
  };
3382
3434
  }
3383
3435
 
@@ -3401,7 +3453,7 @@ class Axios {
3401
3453
 
3402
3454
  config = mergeConfig(this.defaults, config);
3403
3455
 
3404
- const transitional = config.transitional;
3456
+ const {transitional, paramsSerializer, headers} = config;
3405
3457
 
3406
3458
  if (transitional !== undefined) {
3407
3459
  validator.assertOptions(transitional, {
@@ -3411,23 +3463,32 @@ class Axios {
3411
3463
  }, false);
3412
3464
  }
3413
3465
 
3466
+ if (paramsSerializer !== undefined) {
3467
+ validator.assertOptions(paramsSerializer, {
3468
+ encode: validators.function,
3469
+ serialize: validators.function
3470
+ }, true);
3471
+ }
3472
+
3414
3473
  // Set config.method
3415
3474
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3416
3475
 
3476
+ let contextHeaders;
3477
+
3417
3478
  // Flatten headers
3418
- const defaultHeaders = config.headers && utils.merge(
3419
- config.headers.common,
3420
- config.headers[config.method]
3479
+ contextHeaders = headers && utils.merge(
3480
+ headers.common,
3481
+ headers[config.method]
3421
3482
  );
3422
3483
 
3423
- defaultHeaders && utils.forEach(
3484
+ contextHeaders && utils.forEach(
3424
3485
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3425
- function cleanHeaderConfig(method) {
3426
- delete config.headers[method];
3486
+ (method) => {
3487
+ delete headers[method];
3427
3488
  }
3428
3489
  );
3429
3490
 
3430
- config.headers = new AxiosHeaders(config.headers, defaultHeaders);
3491
+ config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
3431
3492
 
3432
3493
  // filter out skipped interceptors
3433
3494
  const requestInterceptorChain = [];
@@ -3539,6 +3600,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3539
3600
  Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
3540
3601
  });
3541
3602
 
3603
+ const Axios$1 = Axios;
3604
+
3542
3605
  /**
3543
3606
  * A `CancelToken` is an object that can be used to request cancellation of an operation.
3544
3607
  *
@@ -3655,6 +3718,8 @@ class CancelToken {
3655
3718
  }
3656
3719
  }
3657
3720
 
3721
+ const CancelToken$1 = CancelToken;
3722
+
3658
3723
  /**
3659
3724
  * Syntactic sugar for invoking a function and expanding an array for arguments.
3660
3725
  *
@@ -3701,11 +3766,11 @@ function isAxiosError(payload) {
3701
3766
  * @returns {Axios} A new instance of Axios
3702
3767
  */
3703
3768
  function createInstance(defaultConfig) {
3704
- const context = new Axios(defaultConfig);
3705
- const instance = bind(Axios.prototype.request, context);
3769
+ const context = new Axios$1(defaultConfig);
3770
+ const instance = bind(Axios$1.prototype.request, context);
3706
3771
 
3707
3772
  // Copy axios.prototype to instance
3708
- utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
3773
+ utils.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
3709
3774
 
3710
3775
  // Copy context to instance
3711
3776
  utils.extend(instance, context, null, {allOwnKeys: true});
@@ -3719,14 +3784,14 @@ function createInstance(defaultConfig) {
3719
3784
  }
3720
3785
 
3721
3786
  // Create the default instance to be exported
3722
- const axios = createInstance(defaults);
3787
+ const axios = createInstance(defaults$1);
3723
3788
 
3724
3789
  // Expose Axios class to allow class inheritance
3725
- axios.Axios = Axios;
3790
+ axios.Axios = Axios$1;
3726
3791
 
3727
3792
  // Expose Cancel & CancelToken
3728
3793
  axios.CanceledError = CanceledError;
3729
- axios.CancelToken = CancelToken;
3794
+ axios.CancelToken = CancelToken$1;
3730
3795
  axios.isCancel = isCancel;
3731
3796
  axios.VERSION = VERSION;
3732
3797
  axios.toFormData = toFormData;
@@ -3747,9 +3812,11 @@ axios.spread = spread;
3747
3812
  // Expose isAxiosError
3748
3813
  axios.isAxiosError = isAxiosError;
3749
3814
 
3750
- axios.formToJSON = thing => {
3751
- return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3752
- };
3815
+ axios.AxiosHeaders = AxiosHeaders$1;
3816
+
3817
+ axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3818
+
3819
+ axios.default = axios;
3753
3820
 
3754
3821
  module.exports = axios;
3755
3822
  //# sourceMappingURL=axios.cjs.map