axios 1.1.3 → 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.3 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
  /**
@@ -1133,6 +1161,8 @@ class InterceptorManager {
1133
1161
  }
1134
1162
  }
1135
1163
 
1164
+ const InterceptorManager$1 = InterceptorManager;
1165
+
1136
1166
  const transitionalDefaults = {
1137
1167
  silentJSONParsing: true,
1138
1168
  forcedJSONParsing: true,
@@ -1320,7 +1350,7 @@ function buildFullPath(baseURL, requestedURL) {
1320
1350
  return requestedURL;
1321
1351
  }
1322
1352
 
1323
- const VERSION = "1.1.3";
1353
+ const VERSION = "1.2.0-alpha.1";
1324
1354
 
1325
1355
  /**
1326
1356
  * A `CanceledError` is an object that is thrown when an operation is canceled.
@@ -1447,7 +1477,6 @@ const parseHeaders = rawHeaders => {
1447
1477
  };
1448
1478
 
1449
1479
  const $internals = Symbol('internals');
1450
- const $defaults = Symbol('defaults');
1451
1480
 
1452
1481
  function normalizeHeader(header) {
1453
1482
  return header && String(header).trim().toLowerCase();
@@ -1473,6 +1502,10 @@ function parseTokens(str) {
1473
1502
  return tokens;
1474
1503
  }
1475
1504
 
1505
+ function isValidHeaderName(str) {
1506
+ return /^[-_a-zA-Z]+$/.test(str.trim());
1507
+ }
1508
+
1476
1509
  function matchHeaderValue(context, value, header, filter) {
1477
1510
  if (utils.isFunction(filter)) {
1478
1511
  return filter.call(this, value, header);
@@ -1509,27 +1542,12 @@ function buildAccessors(obj, header) {
1509
1542
  });
1510
1543
  }
1511
1544
 
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
- }
1545
+ class AxiosHeaders {
1546
+ constructor(headers) {
1547
+ headers && this.set(headers);
1522
1548
  }
1523
- return null;
1524
- }
1525
-
1526
- function AxiosHeaders(headers, defaults) {
1527
- headers && this.set(headers);
1528
- this[$defaults] = defaults || null;
1529
- }
1530
1549
 
1531
- Object.assign(AxiosHeaders.prototype, {
1532
- set: function(header, valueOrRewrite, rewrite) {
1550
+ set(header, valueOrRewrite, rewrite) {
1533
1551
  const self = this;
1534
1552
 
1535
1553
  function setHeader(_value, _header, _rewrite) {
@@ -1539,69 +1557,70 @@ Object.assign(AxiosHeaders.prototype, {
1539
1557
  throw new Error('header name must be a non-empty string');
1540
1558
  }
1541
1559
 
1542
- const key = findKey(self, lHeader);
1560
+ const key = utils.findKey(self, lHeader);
1543
1561
 
1544
- if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
1545
- return;
1562
+ if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
1563
+ self[key || _header] = normalizeValue(_value);
1546
1564
  }
1547
-
1548
- self[key || _header] = normalizeValue(_value);
1549
1565
  }
1550
1566
 
1551
- if (utils.isPlainObject(header)) {
1552
- utils.forEach(header, (_value, _header) => {
1553
- setHeader(_value, _header, valueOrRewrite);
1554
- });
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);
1555
1574
  } else {
1556
- setHeader(valueOrRewrite, header, rewrite);
1575
+ header != null && setHeader(valueOrRewrite, header, rewrite);
1557
1576
  }
1558
1577
 
1559
1578
  return this;
1560
- },
1579
+ }
1561
1580
 
1562
- get: function(header, parser) {
1581
+ get(header, parser) {
1563
1582
  header = normalizeHeader(header);
1564
1583
 
1565
- if (!header) return undefined;
1584
+ if (header) {
1585
+ const key = utils.findKey(this, header);
1566
1586
 
1567
- const key = findKey(this, header);
1587
+ if (key) {
1588
+ const value = this[key];
1568
1589
 
1569
- if (key) {
1570
- const value = this[key];
1590
+ if (!parser) {
1591
+ return value;
1592
+ }
1571
1593
 
1572
- if (!parser) {
1573
- return value;
1574
- }
1594
+ if (parser === true) {
1595
+ return parseTokens(value);
1596
+ }
1575
1597
 
1576
- if (parser === true) {
1577
- return parseTokens(value);
1578
- }
1598
+ if (utils.isFunction(parser)) {
1599
+ return parser.call(this, value, key);
1600
+ }
1579
1601
 
1580
- if (utils.isFunction(parser)) {
1581
- return parser.call(this, value, key);
1582
- }
1602
+ if (utils.isRegExp(parser)) {
1603
+ return parser.exec(value);
1604
+ }
1583
1605
 
1584
- if (utils.isRegExp(parser)) {
1585
- return parser.exec(value);
1606
+ throw new TypeError('parser must be boolean|regexp|function');
1586
1607
  }
1587
-
1588
- throw new TypeError('parser must be boolean|regexp|function');
1589
1608
  }
1590
- },
1609
+ }
1591
1610
 
1592
- has: function(header, matcher) {
1611
+ has(header, matcher) {
1593
1612
  header = normalizeHeader(header);
1594
1613
 
1595
1614
  if (header) {
1596
- const key = findKey(this, header);
1615
+ const key = utils.findKey(this, header);
1597
1616
 
1598
1617
  return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1599
1618
  }
1600
1619
 
1601
1620
  return false;
1602
- },
1621
+ }
1603
1622
 
1604
- delete: function(header, matcher) {
1623
+ delete(header, matcher) {
1605
1624
  const self = this;
1606
1625
  let deleted = false;
1607
1626
 
@@ -1609,7 +1628,7 @@ Object.assign(AxiosHeaders.prototype, {
1609
1628
  _header = normalizeHeader(_header);
1610
1629
 
1611
1630
  if (_header) {
1612
- const key = findKey(self, _header);
1631
+ const key = utils.findKey(self, _header);
1613
1632
 
1614
1633
  if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1615
1634
  delete self[key];
@@ -1626,18 +1645,18 @@ Object.assign(AxiosHeaders.prototype, {
1626
1645
  }
1627
1646
 
1628
1647
  return deleted;
1629
- },
1648
+ }
1630
1649
 
1631
- clear: function() {
1650
+ clear() {
1632
1651
  return Object.keys(this).forEach(this.delete.bind(this));
1633
- },
1652
+ }
1634
1653
 
1635
- normalize: function(format) {
1654
+ normalize(format) {
1636
1655
  const self = this;
1637
1656
  const headers = {};
1638
1657
 
1639
1658
  utils.forEach(this, (value, header) => {
1640
- const key = findKey(headers, header);
1659
+ const key = utils.findKey(headers, header);
1641
1660
 
1642
1661
  if (key) {
1643
1662
  self[key] = normalizeValue(value);
@@ -1657,30 +1676,47 @@ Object.assign(AxiosHeaders.prototype, {
1657
1676
  });
1658
1677
 
1659
1678
  return this;
1660
- },
1679
+ }
1661
1680
 
1662
- toJSON: function(asStrings) {
1681
+ concat(...targets) {
1682
+ return this.constructor.concat(this, ...targets);
1683
+ }
1684
+
1685
+ toJSON(asStrings) {
1663
1686
  const obj = Object.create(null);
1664
1687
 
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
- });
1688
+ utils.forEach(this, (value, header) => {
1689
+ value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
1690
+ });
1670
1691
 
1671
1692
  return obj;
1672
1693
  }
1673
- });
1674
1694
 
1675
- Object.assign(AxiosHeaders, {
1676
- from: function(thing) {
1677
- if (utils.isString(thing)) {
1678
- return new this(parseHeaders(thing));
1679
- }
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) {
1680
1708
  return thing instanceof this ? thing : new this(thing);
1681
- },
1709
+ }
1682
1710
 
1683
- accessor: function(header) {
1711
+ static concat(first, ...targets) {
1712
+ const computed = new this(first);
1713
+
1714
+ targets.forEach((target) => computed.set(target));
1715
+
1716
+ return computed;
1717
+ }
1718
+
1719
+ static accessor(header) {
1684
1720
  const internals = this[$internals] = (this[$internals] = {
1685
1721
  accessors: {}
1686
1722
  });
@@ -1701,13 +1737,15 @@ Object.assign(AxiosHeaders, {
1701
1737
 
1702
1738
  return this;
1703
1739
  }
1704
- });
1740
+ }
1705
1741
 
1706
1742
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1707
1743
 
1708
1744
  utils.freezeMethods(AxiosHeaders.prototype);
1709
1745
  utils.freezeMethods(AxiosHeaders);
1710
1746
 
1747
+ const AxiosHeaders$1 = AxiosHeaders;
1748
+
1711
1749
  /**
1712
1750
  * Throttle decorator
1713
1751
  * @param {Function} fn
@@ -1973,6 +2011,8 @@ class AxiosTransformStream extends stream__default["default"].Transform{
1973
2011
  }
1974
2012
  }
1975
2013
 
2014
+ const AxiosTransformStream$1 = AxiosTransformStream;
2015
+
1976
2016
  const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
1977
2017
 
1978
2018
  const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
@@ -2156,7 +2196,7 @@ function httpAdapter(config) {
2156
2196
  data: convertedData,
2157
2197
  status: 200,
2158
2198
  statusText: 'OK',
2159
- headers: {},
2199
+ headers: new AxiosHeaders$1(),
2160
2200
  config
2161
2201
  });
2162
2202
  }
@@ -2169,7 +2209,7 @@ function httpAdapter(config) {
2169
2209
  ));
2170
2210
  }
2171
2211
 
2172
- const headers = AxiosHeaders.from(config.headers).normalize();
2212
+ const headers = AxiosHeaders$1.from(config.headers).normalize();
2173
2213
 
2174
2214
  // Set User-Agent (required by some servers)
2175
2215
  // See https://github.com/axios/axios/issues/69
@@ -2225,7 +2265,7 @@ function httpAdapter(config) {
2225
2265
  data = stream__default["default"].Readable.from(data, {objectMode: false});
2226
2266
  }
2227
2267
 
2228
- data = stream__default["default"].pipeline([data, new AxiosTransformStream({
2268
+ data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
2229
2269
  length: utils.toFiniteNumber(contentLength),
2230
2270
  maxRate: utils.toFiniteNumber(maxUploadRate)
2231
2271
  })], utils.noop);
@@ -2360,7 +2400,7 @@ function httpAdapter(config) {
2360
2400
  if (onDownloadProgress) {
2361
2401
  const responseLength = +res.headers['content-length'];
2362
2402
 
2363
- const transformStream = new AxiosTransformStream({
2403
+ const transformStream = new AxiosTransformStream$1({
2364
2404
  length: utils.toFiniteNumber(responseLength),
2365
2405
  maxRate: utils.toFiniteNumber(maxDownloadRate)
2366
2406
  });
@@ -2384,7 +2424,7 @@ function httpAdapter(config) {
2384
2424
  const response = {
2385
2425
  status: res.statusCode,
2386
2426
  statusText: res.statusMessage,
2387
- headers: new AxiosHeaders(res.headers),
2427
+ headers: new AxiosHeaders$1(res.headers),
2388
2428
  config,
2389
2429
  request: lastRequest
2390
2430
  };
@@ -2669,7 +2709,8 @@ function progressEventReducer(listener, isDownloadStream) {
2669
2709
  progress: total ? (loaded / total) : undefined,
2670
2710
  bytes: progressBytes,
2671
2711
  rate: rate ? rate : undefined,
2672
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined
2712
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2713
+ event: e
2673
2714
  };
2674
2715
 
2675
2716
  data[isDownloadStream ? 'download' : 'upload'] = true;
@@ -2681,7 +2722,7 @@ function progressEventReducer(listener, isDownloadStream) {
2681
2722
  function xhrAdapter(config) {
2682
2723
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2683
2724
  let requestData = config.data;
2684
- const requestHeaders = AxiosHeaders.from(config.headers).normalize();
2725
+ const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
2685
2726
  const responseType = config.responseType;
2686
2727
  let onCanceled;
2687
2728
  function done() {
@@ -2719,7 +2760,7 @@ function xhrAdapter(config) {
2719
2760
  return;
2720
2761
  }
2721
2762
  // Prepare the response
2722
- const responseHeaders = AxiosHeaders.from(
2763
+ const responseHeaders = AxiosHeaders$1.from(
2723
2764
  'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2724
2765
  );
2725
2766
  const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
@@ -2912,7 +2953,7 @@ const adapters$1 = {
2912
2953
  };
2913
2954
 
2914
2955
  const DEFAULT_CONTENT_TYPE = {
2915
- 'Content-Type': 'application/x-www-form-urlencoded'
2956
+ 'Content-Type': undefined
2916
2957
  };
2917
2958
 
2918
2959
  /**
@@ -3084,6 +3125,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3084
3125
  defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
3085
3126
  });
3086
3127
 
3128
+ const defaults$1 = defaults;
3129
+
3087
3130
  /**
3088
3131
  * Transform the data for a request or a response
3089
3132
  *
@@ -3093,9 +3136,9 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3093
3136
  * @returns {*} The resulting transformed data
3094
3137
  */
3095
3138
  function transformData(fns, response) {
3096
- const config = this || defaults;
3139
+ const config = this || defaults$1;
3097
3140
  const context = response || config;
3098
- const headers = AxiosHeaders.from(context.headers);
3141
+ const headers = AxiosHeaders$1.from(context.headers);
3099
3142
  let data = context.data;
3100
3143
 
3101
3144
  utils.forEach(fns, function transform(fn) {
@@ -3138,7 +3181,7 @@ function throwIfCancellationRequested(config) {
3138
3181
  function dispatchRequest(config) {
3139
3182
  throwIfCancellationRequested(config);
3140
3183
 
3141
- config.headers = AxiosHeaders.from(config.headers);
3184
+ config.headers = AxiosHeaders$1.from(config.headers);
3142
3185
 
3143
3186
  // Transform request data
3144
3187
  config.data = transformData.call(
@@ -3146,7 +3189,11 @@ function dispatchRequest(config) {
3146
3189
  config.transformRequest
3147
3190
  );
3148
3191
 
3149
- 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;
3150
3197
 
3151
3198
  return adapter(config).then(function onAdapterResolution(response) {
3152
3199
  throwIfCancellationRequested(config);
@@ -3158,7 +3205,7 @@ function dispatchRequest(config) {
3158
3205
  response
3159
3206
  );
3160
3207
 
3161
- response.headers = AxiosHeaders.from(response.headers);
3208
+ response.headers = AxiosHeaders$1.from(response.headers);
3162
3209
 
3163
3210
  return response;
3164
3211
  }, function onAdapterRejection(reason) {
@@ -3172,7 +3219,7 @@ function dispatchRequest(config) {
3172
3219
  config.transformResponse,
3173
3220
  reason.response
3174
3221
  );
3175
- reason.response.headers = AxiosHeaders.from(reason.response.headers);
3222
+ reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
3176
3223
  }
3177
3224
  }
3178
3225
 
@@ -3180,6 +3227,8 @@ function dispatchRequest(config) {
3180
3227
  });
3181
3228
  }
3182
3229
 
3230
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
3231
+
3183
3232
  /**
3184
3233
  * Config-specific merge-function which creates a new config-object
3185
3234
  * by merging two configuration objects together.
@@ -3194,9 +3243,9 @@ function mergeConfig(config1, config2) {
3194
3243
  config2 = config2 || {};
3195
3244
  const config = {};
3196
3245
 
3197
- function getMergedValue(target, source) {
3246
+ function getMergedValue(target, source, caseless) {
3198
3247
  if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
3199
- return utils.merge(target, source);
3248
+ return utils.merge.call({caseless}, target, source);
3200
3249
  } else if (utils.isPlainObject(source)) {
3201
3250
  return utils.merge({}, source);
3202
3251
  } else if (utils.isArray(source)) {
@@ -3206,72 +3255,73 @@ function mergeConfig(config1, config2) {
3206
3255
  }
3207
3256
 
3208
3257
  // 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]);
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);
3214
3263
  }
3215
3264
  }
3216
3265
 
3217
3266
  // eslint-disable-next-line consistent-return
3218
- function valueFromConfig2(prop) {
3219
- if (!utils.isUndefined(config2[prop])) {
3220
- return getMergedValue(undefined, config2[prop]);
3267
+ function valueFromConfig2(a, b) {
3268
+ if (!utils.isUndefined(b)) {
3269
+ return getMergedValue(undefined, b);
3221
3270
  }
3222
3271
  }
3223
3272
 
3224
3273
  // 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]);
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);
3230
3279
  }
3231
3280
  }
3232
3281
 
3233
3282
  // eslint-disable-next-line consistent-return
3234
- function mergeDirectKeys(prop) {
3283
+ function mergeDirectKeys(a, b, prop) {
3235
3284
  if (prop in config2) {
3236
- return getMergedValue(config1[prop], config2[prop]);
3285
+ return getMergedValue(a, b);
3237
3286
  } else if (prop in config1) {
3238
- return getMergedValue(undefined, config1[prop]);
3287
+ return getMergedValue(undefined, a);
3239
3288
  }
3240
3289
  }
3241
3290
 
3242
3291
  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
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)
3270
3320
  };
3271
3321
 
3272
3322
  utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
3273
3323
  const merge = mergeMap[prop] || mergeDeepProperties;
3274
- const configValue = merge(prop);
3324
+ const configValue = merge(config1[prop], config2[prop], prop);
3275
3325
  (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
3276
3326
  });
3277
3327
 
@@ -3378,8 +3428,8 @@ class Axios {
3378
3428
  constructor(instanceConfig) {
3379
3429
  this.defaults = instanceConfig;
3380
3430
  this.interceptors = {
3381
- request: new InterceptorManager(),
3382
- response: new InterceptorManager()
3431
+ request: new InterceptorManager$1(),
3432
+ response: new InterceptorManager$1()
3383
3433
  };
3384
3434
  }
3385
3435
 
@@ -3403,7 +3453,7 @@ class Axios {
3403
3453
 
3404
3454
  config = mergeConfig(this.defaults, config);
3405
3455
 
3406
- const {transitional, paramsSerializer} = config;
3456
+ const {transitional, paramsSerializer, headers} = config;
3407
3457
 
3408
3458
  if (transitional !== undefined) {
3409
3459
  validator.assertOptions(transitional, {
@@ -3423,20 +3473,22 @@ class Axios {
3423
3473
  // Set config.method
3424
3474
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3425
3475
 
3476
+ let contextHeaders;
3477
+
3426
3478
  // Flatten headers
3427
- const defaultHeaders = config.headers && utils.merge(
3428
- config.headers.common,
3429
- config.headers[config.method]
3479
+ contextHeaders = headers && utils.merge(
3480
+ headers.common,
3481
+ headers[config.method]
3430
3482
  );
3431
3483
 
3432
- defaultHeaders && utils.forEach(
3484
+ contextHeaders && utils.forEach(
3433
3485
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3434
- function cleanHeaderConfig(method) {
3435
- delete config.headers[method];
3486
+ (method) => {
3487
+ delete headers[method];
3436
3488
  }
3437
3489
  );
3438
3490
 
3439
- config.headers = new AxiosHeaders(config.headers, defaultHeaders);
3491
+ config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
3440
3492
 
3441
3493
  // filter out skipped interceptors
3442
3494
  const requestInterceptorChain = [];
@@ -3548,6 +3600,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3548
3600
  Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
3549
3601
  });
3550
3602
 
3603
+ const Axios$1 = Axios;
3604
+
3551
3605
  /**
3552
3606
  * A `CancelToken` is an object that can be used to request cancellation of an operation.
3553
3607
  *
@@ -3664,6 +3718,8 @@ class CancelToken {
3664
3718
  }
3665
3719
  }
3666
3720
 
3721
+ const CancelToken$1 = CancelToken;
3722
+
3667
3723
  /**
3668
3724
  * Syntactic sugar for invoking a function and expanding an array for arguments.
3669
3725
  *
@@ -3710,11 +3766,11 @@ function isAxiosError(payload) {
3710
3766
  * @returns {Axios} A new instance of Axios
3711
3767
  */
3712
3768
  function createInstance(defaultConfig) {
3713
- const context = new Axios(defaultConfig);
3714
- const instance = bind(Axios.prototype.request, context);
3769
+ const context = new Axios$1(defaultConfig);
3770
+ const instance = bind(Axios$1.prototype.request, context);
3715
3771
 
3716
3772
  // Copy axios.prototype to instance
3717
- utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
3773
+ utils.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
3718
3774
 
3719
3775
  // Copy context to instance
3720
3776
  utils.extend(instance, context, null, {allOwnKeys: true});
@@ -3728,14 +3784,14 @@ function createInstance(defaultConfig) {
3728
3784
  }
3729
3785
 
3730
3786
  // Create the default instance to be exported
3731
- const axios = createInstance(defaults);
3787
+ const axios = createInstance(defaults$1);
3732
3788
 
3733
3789
  // Expose Axios class to allow class inheritance
3734
- axios.Axios = Axios;
3790
+ axios.Axios = Axios$1;
3735
3791
 
3736
3792
  // Expose Cancel & CancelToken
3737
3793
  axios.CanceledError = CanceledError;
3738
- axios.CancelToken = CancelToken;
3794
+ axios.CancelToken = CancelToken$1;
3739
3795
  axios.isCancel = isCancel;
3740
3796
  axios.VERSION = VERSION;
3741
3797
  axios.toFormData = toFormData;
@@ -3756,9 +3812,11 @@ axios.spread = spread;
3756
3812
  // Expose isAxiosError
3757
3813
  axios.isAxiosError = isAxiosError;
3758
3814
 
3759
- axios.formToJSON = thing => {
3760
- return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3761
- };
3815
+ axios.AxiosHeaders = AxiosHeaders$1;
3816
+
3817
+ axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3818
+
3819
+ axios.default = axios;
3762
3820
 
3763
3821
  module.exports = axios;
3764
3822
  //# sourceMappingURL=axios.cjs.map