contentful 11.12.1 → 11.12.2

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.
@@ -12,8 +12,8 @@ var require$$5$1 = require('http2');
12
12
  var require$$4$1 = require('assert');
13
13
  var require$$0$3 = require('tty');
14
14
  var require$$0$2 = require('os');
15
- var require$$8$1 = require('zlib');
16
- var require$$10 = require('events');
15
+ var require$$9 = require('zlib');
16
+ var require$$11 = require('events');
17
17
  var process$1 = require('process');
18
18
 
19
19
  function _OverloadYield(e, d) {
@@ -12533,7 +12533,7 @@ var populate$1 = function (dst, src) {
12533
12533
 
12534
12534
  var CombinedStream = combined_stream;
12535
12535
  var util$1 = require$$1;
12536
- var path = require$$1$1;
12536
+ var path$1 = require$$1$1;
12537
12537
  var http$2 = require$$3;
12538
12538
  var https$2 = require$$4;
12539
12539
  var parseUrl$2 = require$$5.parse;
@@ -12738,17 +12738,17 @@ FormData$2.prototype._getContentDisposition = function (value, options) {
12738
12738
  var filename;
12739
12739
  if (typeof options.filepath === 'string') {
12740
12740
  // custom filepath for relative paths
12741
- filename = path.normalize(options.filepath).replace(/\\/g, '/');
12741
+ filename = path$1.normalize(options.filepath).replace(/\\/g, '/');
12742
12742
  } else if (options.filename || value && (value.name || value.path)) {
12743
12743
  /*
12744
12744
  * custom filename take precedence
12745
12745
  * formidable and the browser add a name property
12746
12746
  * fs- and request- streams have path property
12747
12747
  */
12748
- filename = path.basename(options.filename || value && (value.name || value.path));
12748
+ filename = path$1.basename(options.filename || value && (value.name || value.path));
12749
12749
  } else if (value && value.readable && hasOwn$1(value, 'httpVersion')) {
12750
12750
  // or try http response
12751
- filename = path.basename(value.client._httpMessage.path || '');
12751
+ filename = path$1.basename(value.client._httpMessage.path || '');
12752
12752
  }
12753
12753
  if (filename) {
12754
12754
  return 'filename="' + filename + '"';
@@ -13971,6 +13971,9 @@ try {
13971
13971
  useNativeURL = error.code === "ERR_INVALID_URL";
13972
13972
  }
13973
13973
 
13974
+ // HTTP headers to drop across HTTP/HTTPS and domain boundaries
13975
+ var sensitiveHeaders = ["Authorization", "Proxy-Authorization", "Cookie"];
13976
+
13974
13977
  // URL fields to preserve in copy operations
13975
13978
  var preservedUrlFields = ["auth", "host", "hostname", "href", "path", "pathname", "port", "protocol", "query", "search", "hash"];
13976
13979
 
@@ -14023,6 +14026,9 @@ function RedirectableRequest(options, responseCallback) {
14023
14026
  }
14024
14027
  };
14025
14028
 
14029
+ // Create filter for sensitive HTTP headers
14030
+ this._headerFilter = new RegExp("^(?:" + sensitiveHeaders.concat(options.sensitiveHeaders).map(escapeRegex).join("|") + ")$", "i");
14031
+
14026
14032
  // Perform the first request
14027
14033
  this._performRequest();
14028
14034
  }
@@ -14201,6 +14207,9 @@ RedirectableRequest.prototype._sanitizeOptions = function (options) {
14201
14207
  if (!options.headers) {
14202
14208
  options.headers = {};
14203
14209
  }
14210
+ if (!isArray$8(options.sensitiveHeaders)) {
14211
+ options.sensitiveHeaders = [];
14212
+ }
14204
14213
 
14205
14214
  // Since http.request treats host as an alias of hostname,
14206
14215
  // but the url module interprets host as hostname plus port,
@@ -14376,7 +14385,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
14376
14385
  // Drop confidential headers when redirecting to a less secure protocol
14377
14386
  // or to a different domain that is not a superdomain
14378
14387
  if (redirectUrl.protocol !== currentUrlParts.protocol && redirectUrl.protocol !== "https:" || redirectUrl.host !== currentHost && !isSubdomain(redirectUrl.host, currentHost)) {
14379
- removeMatchingHeaders(/^(?:(?:proxy-)?authorization|cookie)$/i, this._options.headers);
14388
+ removeMatchingHeaders(this._headerFilter, this._options.headers);
14380
14389
  }
14381
14390
 
14382
14391
  // Evaluate the beforeRedirect callback
@@ -14571,6 +14580,9 @@ function isSubdomain(subdomain, domain) {
14571
14580
  var dot = subdomain.length - domain.length - 1;
14572
14581
  return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
14573
14582
  }
14583
+ function isArray$8(value) {
14584
+ return value instanceof Array;
14585
+ }
14574
14586
  function isString$4(value) {
14575
14587
  return typeof value === "string" || value instanceof String;
14576
14588
  }
@@ -14583,6 +14595,9 @@ function isBuffer$2(value) {
14583
14595
  function isURL(value) {
14584
14596
  return URL$1 && value instanceof URL$1;
14585
14597
  }
14598
+ function escapeRegex(regex) {
14599
+ return regex.replace(/[\]\\/()*+?.$]/g, "\\$&");
14600
+ }
14586
14601
 
14587
14602
  // Exports
14588
14603
  followRedirects$1.exports = wrap({
@@ -14599,10 +14614,11 @@ var http = require$$3;
14599
14614
  var https = require$$4;
14600
14615
  var http2 = require$$5$1;
14601
14616
  var util = require$$1;
14617
+ var path = require$$1$1;
14602
14618
  var followRedirects = followRedirectsExports;
14603
- var zlib = require$$8$1;
14619
+ var zlib = require$$9;
14604
14620
  var stream = require$$0$1;
14605
- var events = require$$10;
14621
+ var events = require$$11;
14606
14622
 
14607
14623
  /**
14608
14624
  * Create a bound version of a function with a specified `this` context
@@ -14798,9 +14814,9 @@ const isFile = kindOfTest('File');
14798
14814
  * also have a `name` and `type` attribute to specify filename and content type
14799
14815
  *
14800
14816
  * @see https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/Libraries/Network/FormData.js#L68-L71
14801
- *
14817
+ *
14802
14818
  * @param {*} value The value to test
14803
- *
14819
+ *
14804
14820
  * @returns {boolean} True if value is a React Native Blob, otherwise false
14805
14821
  */
14806
14822
  const isReactNativeBlob = value => {
@@ -14810,9 +14826,9 @@ const isReactNativeBlob = value => {
14810
14826
  /**
14811
14827
  * Determine if environment is React Native
14812
14828
  * ReactNative `FormData` has a non-standard `getParts()` method
14813
- *
14829
+ *
14814
14830
  * @param {*} formData The formData to test
14815
- *
14831
+ *
14816
14832
  * @returns {boolean} True if environment is React Native, otherwise false
14817
14833
  */
14818
14834
  const isReactNative$1 = formData => formData && typeof formData.getParts !== 'undefined';
@@ -14831,7 +14847,7 @@ const isBlob = kindOfTest('Blob');
14831
14847
  *
14832
14848
  * @param {*} val The value to test
14833
14849
  *
14834
- * @returns {boolean} True if value is a File, otherwise false
14850
+ * @returns {boolean} True if value is a FileList, otherwise false
14835
14851
  */
14836
14852
  const isFileList = kindOfTest('FileList');
14837
14853
 
@@ -14861,10 +14877,16 @@ function getGlobal() {
14861
14877
  const G$1 = getGlobal();
14862
14878
  const FormDataCtor = typeof G$1.FormData !== 'undefined' ? G$1.FormData : undefined;
14863
14879
  const isFormData = thing => {
14864
- let kind;
14865
- return thing && (FormDataCtor && thing instanceof FormDataCtor || isFunction$1(thing.append) && ((kind = kindOf(thing)) === 'formdata' ||
14880
+ if (!thing) return false;
14881
+ if (FormDataCtor && thing instanceof FormDataCtor) return true;
14882
+ // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData.
14883
+ const proto = getPrototypeOf$1(thing);
14884
+ if (!proto || proto === Object.prototype) return false;
14885
+ if (!isFunction$1(thing.append)) return false;
14886
+ const kind = kindOf(thing);
14887
+ return kind === 'formdata' ||
14866
14888
  // detect form-data instance
14867
- kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]'));
14889
+ kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]';
14868
14890
  };
14869
14891
 
14870
14892
  /**
@@ -14989,8 +15011,7 @@ const isContextDefined = context => !isUndefined(context) && context !== _global
14989
15011
  *
14990
15012
  * @returns {Object} Result of all merge properties
14991
15013
  */
14992
- function merge$1(/* obj1, obj2, obj3, ... */
14993
- ) {
15014
+ function merge$1(...objs) {
14994
15015
  const {
14995
15016
  caseless,
14996
15017
  skipUndefined
@@ -15002,8 +15023,12 @@ function merge$1(/* obj1, obj2, obj3, ... */
15002
15023
  return;
15003
15024
  }
15004
15025
  const targetKey = caseless && findKey(result, key) || key;
15005
- if (isPlainObject$2(result[targetKey]) && isPlainObject$2(val)) {
15006
- result[targetKey] = merge$1(result[targetKey], val);
15026
+ // Read via own-prop only — a bare `result[targetKey]` walks the prototype
15027
+ // chain, so a polluted Object.prototype value could surface here and get
15028
+ // copied into the merged result.
15029
+ const existing = hasOwnProperty$3(result, targetKey) ? result[targetKey] : undefined;
15030
+ if (isPlainObject$2(existing) && isPlainObject$2(val)) {
15031
+ result[targetKey] = merge$1(existing, val);
15007
15032
  } else if (isPlainObject$2(val)) {
15008
15033
  result[targetKey] = merge$1({}, val);
15009
15034
  } else if (isArray$7(val)) {
@@ -15012,8 +15037,8 @@ function merge$1(/* obj1, obj2, obj3, ... */
15012
15037
  result[targetKey] = val;
15013
15038
  }
15014
15039
  };
15015
- for (let i = 0, l = arguments.length; i < l; i++) {
15016
- arguments[i] && forEach(arguments[i], assignValue);
15040
+ for (let i = 0, l = objs.length; i < l; i++) {
15041
+ objs[i] && forEach(objs[i], assignValue);
15017
15042
  }
15018
15043
  return result;
15019
15044
  }
@@ -15035,6 +15060,9 @@ const extend = (a, b, thisArg, {
15035
15060
  forEach(b, (val, key) => {
15036
15061
  if (thisArg && isFunction$1(val)) {
15037
15062
  Object.defineProperty(a, key, {
15063
+ // Null-proto descriptor so a polluted Object.prototype.get cannot
15064
+ // hijack defineProperty's accessor-vs-data resolution.
15065
+ __proto__: null,
15038
15066
  value: bind(val, thisArg),
15039
15067
  writable: true,
15040
15068
  enumerable: true,
@@ -15042,6 +15070,7 @@ const extend = (a, b, thisArg, {
15042
15070
  });
15043
15071
  } else {
15044
15072
  Object.defineProperty(a, key, {
15073
+ __proto__: null,
15045
15074
  value: val,
15046
15075
  writable: true,
15047
15076
  enumerable: true,
@@ -15080,12 +15109,14 @@ const stripBOM = content => {
15080
15109
  const inherits = (constructor, superConstructor, props, descriptors) => {
15081
15110
  constructor.prototype = Object.create(superConstructor.prototype, descriptors);
15082
15111
  Object.defineProperty(constructor.prototype, 'constructor', {
15112
+ __proto__: null,
15083
15113
  value: constructor,
15084
15114
  writable: true,
15085
15115
  enumerable: false,
15086
15116
  configurable: true
15087
15117
  });
15088
15118
  Object.defineProperty(constructor, 'super', {
15119
+ __proto__: null,
15089
15120
  value: superConstructor.prototype
15090
15121
  });
15091
15122
  props && Object.assign(constructor.prototype, props);
@@ -15253,7 +15284,7 @@ const reduceDescriptors = (obj, reducer) => {
15253
15284
  const freezeMethods = obj => {
15254
15285
  reduceDescriptors(obj, (descriptor, name) => {
15255
15286
  // skip restricted props in strict mode
15256
- if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
15287
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].includes(name)) {
15257
15288
  return false;
15258
15289
  }
15259
15290
  const value = obj[name];
@@ -15459,413 +15490,785 @@ var utils$1$1 = {
15459
15490
  asap,
15460
15491
  isIterable
15461
15492
  };
15462
- class AxiosError extends Error {
15463
- static from(error, code, config, request, response, customProps) {
15464
- const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
15465
- axiosError.cause = error;
15466
- axiosError.name = error.name;
15467
-
15468
- // Preserve status from the original error if not already set from response
15469
- if (error.status != null && axiosError.status == null) {
15470
- axiosError.status = error.status;
15471
- }
15472
- customProps && Object.assign(axiosError, customProps);
15473
- return axiosError;
15474
- }
15475
-
15476
- /**
15477
- * Create an Error with the specified message, config, error code, request and response.
15478
- *
15479
- * @param {string} message The error message.
15480
- * @param {string} [code] The error code (for example, 'ECONNABORTED').
15481
- * @param {Object} [config] The config.
15482
- * @param {Object} [request] The request.
15483
- * @param {Object} [response] The response.
15484
- *
15485
- * @returns {Error} The created error.
15486
- */
15487
- constructor(message, code, config, request, response) {
15488
- super(message);
15489
-
15490
- // Make message enumerable to maintain backward compatibility
15491
- // The native Error constructor sets message as non-enumerable,
15492
- // but axios < v1.13.3 had it as enumerable
15493
- Object.defineProperty(this, 'message', {
15494
- value: message,
15495
- enumerable: true,
15496
- writable: true,
15497
- configurable: true
15498
- });
15499
- this.name = 'AxiosError';
15500
- this.isAxiosError = true;
15501
- code && (this.code = code);
15502
- config && (this.config = config);
15503
- request && (this.request = request);
15504
- if (response) {
15505
- this.response = response;
15506
- this.status = response.status;
15507
- }
15508
- }
15509
- toJSON() {
15510
- return {
15511
- // Standard
15512
- message: this.message,
15513
- name: this.name,
15514
- // Microsoft
15515
- description: this.description,
15516
- number: this.number,
15517
- // Mozilla
15518
- fileName: this.fileName,
15519
- lineNumber: this.lineNumber,
15520
- columnNumber: this.columnNumber,
15521
- stack: this.stack,
15522
- // Axios
15523
- config: utils$1$1.toJSONObject(this.config),
15524
- code: this.code,
15525
- status: this.status
15526
- };
15527
- }
15528
- }
15529
-
15530
- // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated.
15531
- AxiosError.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
15532
- AxiosError.ERR_BAD_OPTION = 'ERR_BAD_OPTION';
15533
- AxiosError.ECONNABORTED = 'ECONNABORTED';
15534
- AxiosError.ETIMEDOUT = 'ETIMEDOUT';
15535
- AxiosError.ERR_NETWORK = 'ERR_NETWORK';
15536
- AxiosError.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
15537
- AxiosError.ERR_DEPRECATED = 'ERR_DEPRECATED';
15538
- AxiosError.ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
15539
- AxiosError.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
15540
- AxiosError.ERR_CANCELED = 'ERR_CANCELED';
15541
- AxiosError.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
15542
- AxiosError.ERR_INVALID_URL = 'ERR_INVALID_URL';
15543
-
15544
- /**
15545
- * Determines if the given thing is a array or js object.
15546
- *
15547
- * @param {string} thing - The object or array to be visited.
15548
- *
15549
- * @returns {boolean}
15550
- */
15551
- function isVisitable(thing) {
15552
- return utils$1$1.isPlainObject(thing) || utils$1$1.isArray(thing);
15553
- }
15554
-
15555
- /**
15556
- * It removes the brackets from the end of a string
15557
- *
15558
- * @param {string} key - The key of the parameter.
15559
- *
15560
- * @returns {string} the key without the brackets.
15561
- */
15562
- function removeBrackets(key) {
15563
- return utils$1$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
15564
- }
15565
-
15566
- /**
15567
- * It takes a path, a key, and a boolean, and returns a string
15568
- *
15569
- * @param {string} path - The path to the current key.
15570
- * @param {string} key - The key of the current object being iterated over.
15571
- * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
15572
- *
15573
- * @returns {string} The path to the current key.
15574
- */
15575
- function renderKey(path, key, dots) {
15576
- if (!path) return key;
15577
- return path.concat(key).map(function each(token, i) {
15578
- // eslint-disable-next-line no-param-reassign
15579
- token = removeBrackets(token);
15580
- return !dots && i ? '[' + token + ']' : token;
15581
- }).join(dots ? '.' : '');
15582
- }
15583
15493
 
15584
- /**
15585
- * If the array is an array and none of its elements are visitable, then it's a flat array.
15586
- *
15587
- * @param {Array<any>} arr - The array to check
15588
- *
15589
- * @returns {boolean}
15590
- */
15591
- function isFlatArray(arr) {
15592
- return utils$1$1.isArray(arr) && !arr.some(isVisitable);
15593
- }
15594
- const predicates = utils$1$1.toFlatObject(utils$1$1, {}, null, function filter(prop) {
15595
- return /^is[A-Z]/.test(prop);
15596
- });
15494
+ // RawAxiosHeaders whose duplicates are ignored by node
15495
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
15496
+ const ignoreDuplicateOf = utils$1$1.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
15597
15497
 
15598
15498
  /**
15599
- * Convert a data object to FormData
15600
- *
15601
- * @param {Object} obj
15602
- * @param {?Object} [formData]
15603
- * @param {?Object} [options]
15604
- * @param {Function} [options.visitor]
15605
- * @param {Boolean} [options.metaTokens = true]
15606
- * @param {Boolean} [options.dots = false]
15607
- * @param {?Boolean} [options.indexes = false]
15499
+ * Parse headers into an object
15608
15500
  *
15609
- * @returns {Object}
15610
- **/
15611
-
15612
- /**
15613
- * It converts an object into a FormData object
15501
+ * ```
15502
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
15503
+ * Content-Type: application/json
15504
+ * Connection: keep-alive
15505
+ * Transfer-Encoding: chunked
15506
+ * ```
15614
15507
  *
15615
- * @param {Object<any, any>} obj - The object to convert to form data.
15616
- * @param {string} formData - The FormData object to append to.
15617
- * @param {Object<string, any>} options
15508
+ * @param {String} rawHeaders Headers needing to be parsed
15618
15509
  *
15619
- * @returns
15510
+ * @returns {Object} Headers parsed into an object
15620
15511
  */
15621
- function toFormData(obj, formData, options) {
15622
- if (!utils$1$1.isObject(obj)) {
15623
- throw new TypeError('target must be an object');
15624
- }
15625
-
15626
- // eslint-disable-next-line no-param-reassign
15627
- formData = formData || new (FormData$1 || FormData)();
15628
-
15629
- // eslint-disable-next-line no-param-reassign
15630
- options = utils$1$1.toFlatObject(options, {
15631
- metaTokens: true,
15632
- dots: false,
15633
- indexes: false
15634
- }, false, function defined(option, source) {
15635
- // eslint-disable-next-line no-eq-null,eqeqeq
15636
- return !utils$1$1.isUndefined(source[option]);
15637
- });
15638
- const metaTokens = options.metaTokens;
15639
- // eslint-disable-next-line no-use-before-define
15640
- const visitor = options.visitor || defaultVisitor;
15641
- const dots = options.dots;
15642
- const indexes = options.indexes;
15643
- const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
15644
- const useBlob = _Blob && utils$1$1.isSpecCompliantForm(formData);
15645
- if (!utils$1$1.isFunction(visitor)) {
15646
- throw new TypeError('visitor must be a function');
15647
- }
15648
- function convertValue(value) {
15649
- if (value === null) return '';
15650
- if (utils$1$1.isDate(value)) {
15651
- return value.toISOString();
15512
+ var parseHeaders = rawHeaders => {
15513
+ const parsed = {};
15514
+ let key;
15515
+ let val;
15516
+ let i;
15517
+ rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
15518
+ i = line.indexOf(':');
15519
+ key = line.substring(0, i).trim().toLowerCase();
15520
+ val = line.substring(i + 1).trim();
15521
+ if (!key || parsed[key] && ignoreDuplicateOf[key]) {
15522
+ return;
15652
15523
  }
15653
- if (utils$1$1.isBoolean(value)) {
15654
- return value.toString();
15524
+ if (key === 'set-cookie') {
15525
+ if (parsed[key]) {
15526
+ parsed[key].push(val);
15527
+ } else {
15528
+ parsed[key] = [val];
15529
+ }
15530
+ } else {
15531
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
15655
15532
  }
15656
- if (!useBlob && utils$1$1.isBlob(value)) {
15657
- throw new AxiosError('Blob is not supported. Use a Buffer instead.');
15533
+ });
15534
+ return parsed;
15535
+ };
15536
+ const $internals = Symbol('internals');
15537
+ const INVALID_HEADER_VALUE_CHARS_RE = /[^\x09\x20-\x7E\x80-\xFF]/g;
15538
+ function trimSPorHTAB(str) {
15539
+ let start = 0;
15540
+ let end = str.length;
15541
+ while (start < end) {
15542
+ const code = str.charCodeAt(start);
15543
+ if (code !== 0x09 && code !== 0x20) {
15544
+ break;
15658
15545
  }
15659
- if (utils$1$1.isArrayBuffer(value) || utils$1$1.isTypedArray(value)) {
15660
- return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
15546
+ start += 1;
15547
+ }
15548
+ while (end > start) {
15549
+ const code = str.charCodeAt(end - 1);
15550
+ if (code !== 0x09 && code !== 0x20) {
15551
+ break;
15661
15552
  }
15553
+ end -= 1;
15554
+ }
15555
+ return start === 0 && end === str.length ? str : str.slice(start, end);
15556
+ }
15557
+ function normalizeHeader(header) {
15558
+ return header && String(header).trim().toLowerCase();
15559
+ }
15560
+ function sanitizeHeaderValue(str) {
15561
+ return trimSPorHTAB(str.replace(INVALID_HEADER_VALUE_CHARS_RE, ''));
15562
+ }
15563
+ function normalizeValue(value) {
15564
+ if (value === false || value == null) {
15662
15565
  return value;
15663
15566
  }
15664
-
15665
- /**
15666
- * Default visitor.
15667
- *
15668
- * @param {*} value
15669
- * @param {String|Number} key
15670
- * @param {Array<String|Number>} path
15671
- * @this {FormData}
15672
- *
15673
- * @returns {boolean} return true to visit the each prop of the value recursively
15674
- */
15675
- function defaultVisitor(value, key, path) {
15676
- let arr = value;
15677
- if (utils$1$1.isReactNative(formData) && utils$1$1.isReactNativeBlob(value)) {
15678
- formData.append(renderKey(path, key, dots), convertValue(value));
15679
- return false;
15567
+ return utils$1$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
15568
+ }
15569
+ function parseTokens(str) {
15570
+ const tokens = Object.create(null);
15571
+ const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
15572
+ let match;
15573
+ while (match = tokensRE.exec(str)) {
15574
+ tokens[match[1]] = match[2];
15575
+ }
15576
+ return tokens;
15577
+ }
15578
+ const isValidHeaderName = str => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
15579
+ function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
15580
+ if (utils$1$1.isFunction(filter)) {
15581
+ return filter.call(this, value, header);
15582
+ }
15583
+ if (isHeaderNameFilter) {
15584
+ value = header;
15585
+ }
15586
+ if (!utils$1$1.isString(value)) return;
15587
+ if (utils$1$1.isString(filter)) {
15588
+ return value.indexOf(filter) !== -1;
15589
+ }
15590
+ if (utils$1$1.isRegExp(filter)) {
15591
+ return filter.test(value);
15592
+ }
15593
+ }
15594
+ function formatHeader(header) {
15595
+ return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
15596
+ return char.toUpperCase() + str;
15597
+ });
15598
+ }
15599
+ function buildAccessors(obj, header) {
15600
+ const accessorName = utils$1$1.toCamelCase(' ' + header);
15601
+ ['get', 'set', 'has'].forEach(methodName => {
15602
+ Object.defineProperty(obj, methodName + accessorName, {
15603
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
15604
+ // this data descriptor into an accessor descriptor on the way in.
15605
+ __proto__: null,
15606
+ value: function (arg1, arg2, arg3) {
15607
+ return this[methodName].call(this, header, arg1, arg2, arg3);
15608
+ },
15609
+ configurable: true
15610
+ });
15611
+ });
15612
+ }
15613
+ class AxiosHeaders {
15614
+ constructor(headers) {
15615
+ headers && this.set(headers);
15616
+ }
15617
+ set(header, valueOrRewrite, rewrite) {
15618
+ const self = this;
15619
+ function setHeader(_value, _header, _rewrite) {
15620
+ const lHeader = normalizeHeader(_header);
15621
+ if (!lHeader) {
15622
+ throw new Error('header name must be a non-empty string');
15623
+ }
15624
+ const key = utils$1$1.findKey(self, lHeader);
15625
+ if (!key || self[key] === undefined || _rewrite === true || _rewrite === undefined && self[key] !== false) {
15626
+ self[key || _header] = normalizeValue(_value);
15627
+ }
15680
15628
  }
15681
- if (value && !path && typeof value === 'object') {
15682
- if (utils$1$1.endsWith(key, '{}')) {
15683
- // eslint-disable-next-line no-param-reassign
15684
- key = metaTokens ? key : key.slice(0, -2);
15685
- // eslint-disable-next-line no-param-reassign
15686
- value = JSON.stringify(value);
15687
- } else if (utils$1$1.isArray(value) && isFlatArray(value) || (utils$1$1.isFileList(value) || utils$1$1.endsWith(key, '[]')) && (arr = utils$1$1.toArray(value))) {
15688
- // eslint-disable-next-line no-param-reassign
15689
- key = removeBrackets(key);
15690
- arr.forEach(function each(el, index) {
15691
- !(utils$1$1.isUndefined(el) || el === null) && formData.append(
15692
- // eslint-disable-next-line no-nested-ternary
15693
- indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + '[]', convertValue(el));
15694
- });
15695
- return false;
15629
+ const setHeaders = (headers, _rewrite) => utils$1$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
15630
+ if (utils$1$1.isPlainObject(header) || header instanceof this.constructor) {
15631
+ setHeaders(header, valueOrRewrite);
15632
+ } else if (utils$1$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
15633
+ setHeaders(parseHeaders(header), valueOrRewrite);
15634
+ } else if (utils$1$1.isObject(header) && utils$1$1.isIterable(header)) {
15635
+ let obj = {},
15636
+ dest,
15637
+ key;
15638
+ for (const entry of header) {
15639
+ if (!utils$1$1.isArray(entry)) {
15640
+ throw TypeError('Object iterator must return a key-value pair');
15641
+ }
15642
+ obj[key = entry[0]] = (dest = obj[key]) ? utils$1$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]] : entry[1];
15696
15643
  }
15644
+ setHeaders(obj, valueOrRewrite);
15645
+ } else {
15646
+ header != null && setHeader(valueOrRewrite, header, rewrite);
15697
15647
  }
15698
- if (isVisitable(value)) {
15699
- return true;
15648
+ return this;
15649
+ }
15650
+ get(header, parser) {
15651
+ header = normalizeHeader(header);
15652
+ if (header) {
15653
+ const key = utils$1$1.findKey(this, header);
15654
+ if (key) {
15655
+ const value = this[key];
15656
+ if (!parser) {
15657
+ return value;
15658
+ }
15659
+ if (parser === true) {
15660
+ return parseTokens(value);
15661
+ }
15662
+ if (utils$1$1.isFunction(parser)) {
15663
+ return parser.call(this, value, key);
15664
+ }
15665
+ if (utils$1$1.isRegExp(parser)) {
15666
+ return parser.exec(value);
15667
+ }
15668
+ throw new TypeError('parser must be boolean|regexp|function');
15669
+ }
15670
+ }
15671
+ }
15672
+ has(header, matcher) {
15673
+ header = normalizeHeader(header);
15674
+ if (header) {
15675
+ const key = utils$1$1.findKey(this, header);
15676
+ return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
15700
15677
  }
15701
- formData.append(renderKey(path, key, dots), convertValue(value));
15702
15678
  return false;
15703
15679
  }
15704
- const stack = [];
15705
- const exposedHelpers = Object.assign(predicates, {
15706
- defaultVisitor,
15707
- convertValue,
15708
- isVisitable
15709
- });
15710
- function build(value, path) {
15711
- if (utils$1$1.isUndefined(value)) return;
15712
- if (stack.indexOf(value) !== -1) {
15713
- throw Error('Circular reference detected in ' + path.join('.'));
15680
+ delete(header, matcher) {
15681
+ const self = this;
15682
+ let deleted = false;
15683
+ function deleteHeader(_header) {
15684
+ _header = normalizeHeader(_header);
15685
+ if (_header) {
15686
+ const key = utils$1$1.findKey(self, _header);
15687
+ if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
15688
+ delete self[key];
15689
+ deleted = true;
15690
+ }
15691
+ }
15714
15692
  }
15715
- stack.push(value);
15716
- utils$1$1.forEach(value, function each(el, key) {
15717
- const result = !(utils$1$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1$1.isString(key) ? key.trim() : key, path, exposedHelpers);
15718
- if (result === true) {
15719
- build(el, path ? path.concat(key) : [key]);
15693
+ if (utils$1$1.isArray(header)) {
15694
+ header.forEach(deleteHeader);
15695
+ } else {
15696
+ deleteHeader(header);
15697
+ }
15698
+ return deleted;
15699
+ }
15700
+ clear(matcher) {
15701
+ const keys = Object.keys(this);
15702
+ let i = keys.length;
15703
+ let deleted = false;
15704
+ while (i--) {
15705
+ const key = keys[i];
15706
+ if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
15707
+ delete this[key];
15708
+ deleted = true;
15709
+ }
15710
+ }
15711
+ return deleted;
15712
+ }
15713
+ normalize(format) {
15714
+ const self = this;
15715
+ const headers = {};
15716
+ utils$1$1.forEach(this, (value, header) => {
15717
+ const key = utils$1$1.findKey(headers, header);
15718
+ if (key) {
15719
+ self[key] = normalizeValue(value);
15720
+ delete self[header];
15721
+ return;
15722
+ }
15723
+ const normalized = format ? formatHeader(header) : String(header).trim();
15724
+ if (normalized !== header) {
15725
+ delete self[header];
15720
15726
  }
15727
+ self[normalized] = normalizeValue(value);
15728
+ headers[normalized] = true;
15721
15729
  });
15722
- stack.pop();
15730
+ return this;
15723
15731
  }
15724
- if (!utils$1$1.isObject(obj)) {
15725
- throw new TypeError('data must be an object');
15732
+ concat(...targets) {
15733
+ return this.constructor.concat(this, ...targets);
15734
+ }
15735
+ toJSON(asStrings) {
15736
+ const obj = Object.create(null);
15737
+ utils$1$1.forEach(this, (value, header) => {
15738
+ value != null && value !== false && (obj[header] = asStrings && utils$1$1.isArray(value) ? value.join(', ') : value);
15739
+ });
15740
+ return obj;
15741
+ }
15742
+ [Symbol.iterator]() {
15743
+ return Object.entries(this.toJSON())[Symbol.iterator]();
15744
+ }
15745
+ toString() {
15746
+ return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
15747
+ }
15748
+ getSetCookie() {
15749
+ return this.get('set-cookie') || [];
15750
+ }
15751
+ get [Symbol.toStringTag]() {
15752
+ return 'AxiosHeaders';
15753
+ }
15754
+ static from(thing) {
15755
+ return thing instanceof this ? thing : new this(thing);
15756
+ }
15757
+ static concat(first, ...targets) {
15758
+ const computed = new this(first);
15759
+ targets.forEach(target => computed.set(target));
15760
+ return computed;
15761
+ }
15762
+ static accessor(header) {
15763
+ const internals = this[$internals] = this[$internals] = {
15764
+ accessors: {}
15765
+ };
15766
+ const accessors = internals.accessors;
15767
+ const prototype = this.prototype;
15768
+ function defineAccessor(_header) {
15769
+ const lHeader = normalizeHeader(_header);
15770
+ if (!accessors[lHeader]) {
15771
+ buildAccessors(prototype, _header);
15772
+ accessors[lHeader] = true;
15773
+ }
15774
+ }
15775
+ utils$1$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
15776
+ return this;
15726
15777
  }
15727
- build(obj);
15728
- return formData;
15729
15778
  }
15779
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
15730
15780
 
15731
- /**
15732
- * It encodes a string by replacing all characters that are not in the unreserved set with
15733
- * their percent-encoded equivalents
15734
- *
15735
- * @param {string} str - The string to encode.
15736
- *
15737
- * @returns {string} The encoded string.
15738
- */
15739
- function encode$1(str) {
15740
- const charMap = {
15741
- '!': '%21',
15742
- "'": '%27',
15743
- '(': '%28',
15744
- ')': '%29',
15745
- '~': '%7E',
15746
- '%20': '+',
15747
- '%00': '\x00'
15781
+ // reserved names hotfix
15782
+ utils$1$1.reduceDescriptors(AxiosHeaders.prototype, ({
15783
+ value
15784
+ }, key) => {
15785
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
15786
+ return {
15787
+ get: () => value,
15788
+ set(headerValue) {
15789
+ this[mapped] = headerValue;
15790
+ }
15748
15791
  };
15749
- return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
15750
- return charMap[match];
15751
- });
15792
+ });
15793
+ utils$1$1.freezeMethods(AxiosHeaders);
15794
+ const REDACTED = '[REDACTED ****]';
15795
+ function hasOwnOrPrototypeToJSON(source) {
15796
+ if (utils$1$1.hasOwnProp(source, 'toJSON')) {
15797
+ return true;
15798
+ }
15799
+ let prototype = Object.getPrototypeOf(source);
15800
+ while (prototype && prototype !== Object.prototype) {
15801
+ if (utils$1$1.hasOwnProp(prototype, 'toJSON')) {
15802
+ return true;
15803
+ }
15804
+ prototype = Object.getPrototypeOf(prototype);
15805
+ }
15806
+ return false;
15807
+ }
15808
+
15809
+ // Build a plain-object snapshot of `config` and replace the value of any key
15810
+ // (case-insensitive) listed in `redactKeys` with REDACTED. Walks through arrays
15811
+ // and AxiosHeaders, and short-circuits on circular references.
15812
+ function redactConfig(config, redactKeys) {
15813
+ const lowerKeys = new Set(redactKeys.map(k => String(k).toLowerCase()));
15814
+ const seen = [];
15815
+ const visit = source => {
15816
+ if (source === null || typeof source !== 'object') return source;
15817
+ if (utils$1$1.isBuffer(source)) return source;
15818
+ if (seen.indexOf(source) !== -1) return undefined;
15819
+ if (source instanceof AxiosHeaders) {
15820
+ source = source.toJSON();
15821
+ }
15822
+ seen.push(source);
15823
+ let result;
15824
+ if (utils$1$1.isArray(source)) {
15825
+ result = [];
15826
+ source.forEach((v, i) => {
15827
+ const reducedValue = visit(v);
15828
+ if (!utils$1$1.isUndefined(reducedValue)) {
15829
+ result[i] = reducedValue;
15830
+ }
15831
+ });
15832
+ } else {
15833
+ if (!utils$1$1.isPlainObject(source) && hasOwnOrPrototypeToJSON(source)) {
15834
+ seen.pop();
15835
+ return source;
15836
+ }
15837
+ result = Object.create(null);
15838
+ for (const [key, value] of Object.entries(source)) {
15839
+ const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
15840
+ if (!utils$1$1.isUndefined(reducedValue)) {
15841
+ result[key] = reducedValue;
15842
+ }
15843
+ }
15844
+ }
15845
+ seen.pop();
15846
+ return result;
15847
+ };
15848
+ return visit(config);
15849
+ }
15850
+ class AxiosError extends Error {
15851
+ static from(error, code, config, request, response, customProps) {
15852
+ const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
15853
+ axiosError.cause = error;
15854
+ axiosError.name = error.name;
15855
+
15856
+ // Preserve status from the original error if not already set from response
15857
+ if (error.status != null && axiosError.status == null) {
15858
+ axiosError.status = error.status;
15859
+ }
15860
+ customProps && Object.assign(axiosError, customProps);
15861
+ return axiosError;
15862
+ }
15863
+
15864
+ /**
15865
+ * Create an Error with the specified message, config, error code, request and response.
15866
+ *
15867
+ * @param {string} message The error message.
15868
+ * @param {string} [code] The error code (for example, 'ECONNABORTED').
15869
+ * @param {Object} [config] The config.
15870
+ * @param {Object} [request] The request.
15871
+ * @param {Object} [response] The response.
15872
+ *
15873
+ * @returns {Error} The created error.
15874
+ */
15875
+ constructor(message, code, config, request, response) {
15876
+ super(message);
15877
+
15878
+ // Make message enumerable to maintain backward compatibility
15879
+ // The native Error constructor sets message as non-enumerable,
15880
+ // but axios < v1.13.3 had it as enumerable
15881
+ Object.defineProperty(this, 'message', {
15882
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
15883
+ // this data descriptor into an accessor descriptor on the way in.
15884
+ __proto__: null,
15885
+ value: message,
15886
+ enumerable: true,
15887
+ writable: true,
15888
+ configurable: true
15889
+ });
15890
+ this.name = 'AxiosError';
15891
+ this.isAxiosError = true;
15892
+ code && (this.code = code);
15893
+ config && (this.config = config);
15894
+ request && (this.request = request);
15895
+ if (response) {
15896
+ this.response = response;
15897
+ this.status = response.status;
15898
+ }
15899
+ }
15900
+ toJSON() {
15901
+ // Opt-in redaction: when the request config carries a `redact` array, the
15902
+ // value of any matching key (case-insensitive, at any depth) is replaced
15903
+ // with REDACTED in the serialized snapshot. Undefined or empty leaves the
15904
+ // existing serialization behavior unchanged.
15905
+ const config = this.config;
15906
+ const redactKeys = config && utils$1$1.hasOwnProp(config, 'redact') ? config.redact : undefined;
15907
+ const serializedConfig = utils$1$1.isArray(redactKeys) && redactKeys.length > 0 ? redactConfig(config, redactKeys) : utils$1$1.toJSONObject(config);
15908
+ return {
15909
+ // Standard
15910
+ message: this.message,
15911
+ name: this.name,
15912
+ // Microsoft
15913
+ description: this.description,
15914
+ number: this.number,
15915
+ // Mozilla
15916
+ fileName: this.fileName,
15917
+ lineNumber: this.lineNumber,
15918
+ columnNumber: this.columnNumber,
15919
+ stack: this.stack,
15920
+ // Axios
15921
+ config: serializedConfig,
15922
+ code: this.code,
15923
+ status: this.status
15924
+ };
15925
+ }
15752
15926
  }
15753
15927
 
15928
+ // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated.
15929
+ AxiosError.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
15930
+ AxiosError.ERR_BAD_OPTION = 'ERR_BAD_OPTION';
15931
+ AxiosError.ECONNABORTED = 'ECONNABORTED';
15932
+ AxiosError.ETIMEDOUT = 'ETIMEDOUT';
15933
+ AxiosError.ECONNREFUSED = 'ECONNREFUSED';
15934
+ AxiosError.ERR_NETWORK = 'ERR_NETWORK';
15935
+ AxiosError.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
15936
+ AxiosError.ERR_DEPRECATED = 'ERR_DEPRECATED';
15937
+ AxiosError.ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
15938
+ AxiosError.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
15939
+ AxiosError.ERR_CANCELED = 'ERR_CANCELED';
15940
+ AxiosError.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
15941
+ AxiosError.ERR_INVALID_URL = 'ERR_INVALID_URL';
15942
+ AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
15943
+
15754
15944
  /**
15755
- * It takes a params object and converts it to a FormData object
15945
+ * Determines if the given thing is a array or js object.
15756
15946
  *
15757
- * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
15758
- * @param {Object<string, any>} options - The options object passed to the Axios constructor.
15947
+ * @param {string} thing - The object or array to be visited.
15759
15948
  *
15760
- * @returns {void}
15949
+ * @returns {boolean}
15761
15950
  */
15762
- function AxiosURLSearchParams(params, options) {
15763
- this._pairs = [];
15764
- params && toFormData(params, this, options);
15951
+ function isVisitable(thing) {
15952
+ return utils$1$1.isPlainObject(thing) || utils$1$1.isArray(thing);
15765
15953
  }
15766
- const prototype = AxiosURLSearchParams.prototype;
15767
- prototype.append = function append(name, value) {
15768
- this._pairs.push([name, value]);
15769
- };
15770
- prototype.toString = function toString(encoder) {
15771
- const _encode = encoder ? function (value) {
15772
- return encoder.call(this, value, encode$1);
15773
- } : encode$1;
15774
- return this._pairs.map(function each(pair) {
15775
- return _encode(pair[0]) + '=' + _encode(pair[1]);
15776
- }, '').join('&');
15777
- };
15778
15954
 
15779
15955
  /**
15780
- * It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
15781
- * their plain counterparts (`:`, `$`, `,`, `+`).
15956
+ * It removes the brackets from the end of a string
15782
15957
  *
15783
- * @param {string} val The value to be encoded.
15958
+ * @param {string} key - The key of the parameter.
15784
15959
  *
15785
- * @returns {string} The encoded value.
15960
+ * @returns {string} the key without the brackets.
15786
15961
  */
15787
- function encode$2(val) {
15788
- return encodeURIComponent(val).replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+');
15962
+ function removeBrackets(key) {
15963
+ return utils$1$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
15789
15964
  }
15790
15965
 
15791
15966
  /**
15792
- * Build a URL by appending params to the end
15967
+ * It takes a path, a key, and a boolean, and returns a string
15793
15968
  *
15794
- * @param {string} url The base of the url (e.g., http://www.google.com)
15795
- * @param {object} [params] The params to be appended
15796
- * @param {?(object|Function)} options
15969
+ * @param {string} path - The path to the current key.
15970
+ * @param {string} key - The key of the current object being iterated over.
15971
+ * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
15797
15972
  *
15798
- * @returns {string} The formatted url
15973
+ * @returns {string} The path to the current key.
15799
15974
  */
15800
- function buildURL(url, params, options) {
15801
- if (!params) {
15802
- return url;
15803
- }
15804
- const _encode = options && options.encode || encode$2;
15805
- const _options = utils$1$1.isFunction(options) ? {
15806
- serialize: options
15807
- } : options;
15808
- const serializeFn = _options && _options.serialize;
15809
- let serializedParams;
15810
- if (serializeFn) {
15811
- serializedParams = serializeFn(params, _options);
15812
- } else {
15813
- serializedParams = utils$1$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
15814
- }
15815
- if (serializedParams) {
15816
- const hashmarkIndex = url.indexOf('#');
15817
- if (hashmarkIndex !== -1) {
15818
- url = url.slice(0, hashmarkIndex);
15819
- }
15820
- url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
15821
- }
15822
- return url;
15975
+ function renderKey(path, key, dots) {
15976
+ if (!path) return key;
15977
+ return path.concat(key).map(function each(token, i) {
15978
+ // eslint-disable-next-line no-param-reassign
15979
+ token = removeBrackets(token);
15980
+ return !dots && i ? '[' + token + ']' : token;
15981
+ }).join(dots ? '.' : '');
15823
15982
  }
15824
- class InterceptorManager {
15825
- constructor() {
15826
- this.handlers = [];
15827
- }
15828
15983
 
15829
- /**
15830
- * Add a new interceptor to the stack
15831
- *
15832
- * @param {Function} fulfilled The function to handle `then` for a `Promise`
15833
- * @param {Function} rejected The function to handle `reject` for a `Promise`
15834
- * @param {Object} options The options for the interceptor, synchronous and runWhen
15835
- *
15836
- * @return {Number} An ID used to remove interceptor later
15837
- */
15838
- use(fulfilled, rejected, options) {
15839
- this.handlers.push({
15840
- fulfilled,
15841
- rejected,
15842
- synchronous: options ? options.synchronous : false,
15843
- runWhen: options ? options.runWhen : null
15844
- });
15845
- return this.handlers.length - 1;
15846
- }
15984
+ /**
15985
+ * If the array is an array and none of its elements are visitable, then it's a flat array.
15986
+ *
15987
+ * @param {Array<any>} arr - The array to check
15988
+ *
15989
+ * @returns {boolean}
15990
+ */
15991
+ function isFlatArray(arr) {
15992
+ return utils$1$1.isArray(arr) && !arr.some(isVisitable);
15993
+ }
15994
+ const predicates = utils$1$1.toFlatObject(utils$1$1, {}, null, function filter(prop) {
15995
+ return /^is[A-Z]/.test(prop);
15996
+ });
15847
15997
 
15848
- /**
15849
- * Remove an interceptor from the stack
15850
- *
15851
- * @param {Number} id The ID that was returned by `use`
15852
- *
15853
- * @returns {void}
15854
- */
15855
- eject(id) {
15856
- if (this.handlers[id]) {
15857
- this.handlers[id] = null;
15858
- }
15859
- }
15998
+ /**
15999
+ * Convert a data object to FormData
16000
+ *
16001
+ * @param {Object} obj
16002
+ * @param {?Object} [formData]
16003
+ * @param {?Object} [options]
16004
+ * @param {Function} [options.visitor]
16005
+ * @param {Boolean} [options.metaTokens = true]
16006
+ * @param {Boolean} [options.dots = false]
16007
+ * @param {?Boolean} [options.indexes = false]
16008
+ *
16009
+ * @returns {Object}
16010
+ **/
15860
16011
 
15861
- /**
15862
- * Clear all interceptors from the stack
15863
- *
15864
- * @returns {void}
15865
- */
15866
- clear() {
15867
- if (this.handlers) {
15868
- this.handlers = [];
16012
+ /**
16013
+ * It converts an object into a FormData object
16014
+ *
16015
+ * @param {Object<any, any>} obj - The object to convert to form data.
16016
+ * @param {string} formData - The FormData object to append to.
16017
+ * @param {Object<string, any>} options
16018
+ *
16019
+ * @returns
16020
+ */
16021
+ function toFormData(obj, formData, options) {
16022
+ if (!utils$1$1.isObject(obj)) {
16023
+ throw new TypeError('target must be an object');
16024
+ }
16025
+
16026
+ // eslint-disable-next-line no-param-reassign
16027
+ formData = formData || new (FormData$1 || FormData)();
16028
+
16029
+ // eslint-disable-next-line no-param-reassign
16030
+ options = utils$1$1.toFlatObject(options, {
16031
+ metaTokens: true,
16032
+ dots: false,
16033
+ indexes: false
16034
+ }, false, function defined(option, source) {
16035
+ // eslint-disable-next-line no-eq-null,eqeqeq
16036
+ return !utils$1$1.isUndefined(source[option]);
16037
+ });
16038
+ const metaTokens = options.metaTokens;
16039
+ // eslint-disable-next-line no-use-before-define
16040
+ const visitor = options.visitor || defaultVisitor;
16041
+ const dots = options.dots;
16042
+ const indexes = options.indexes;
16043
+ const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
16044
+ const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
16045
+ const useBlob = _Blob && utils$1$1.isSpecCompliantForm(formData);
16046
+ if (!utils$1$1.isFunction(visitor)) {
16047
+ throw new TypeError('visitor must be a function');
16048
+ }
16049
+ function convertValue(value) {
16050
+ if (value === null) return '';
16051
+ if (utils$1$1.isDate(value)) {
16052
+ return value.toISOString();
16053
+ }
16054
+ if (utils$1$1.isBoolean(value)) {
16055
+ return value.toString();
16056
+ }
16057
+ if (!useBlob && utils$1$1.isBlob(value)) {
16058
+ throw new AxiosError('Blob is not supported. Use a Buffer instead.');
16059
+ }
16060
+ if (utils$1$1.isArrayBuffer(value) || utils$1$1.isTypedArray(value)) {
16061
+ return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
16062
+ }
16063
+ return value;
16064
+ }
16065
+
16066
+ /**
16067
+ * Default visitor.
16068
+ *
16069
+ * @param {*} value
16070
+ * @param {String|Number} key
16071
+ * @param {Array<String|Number>} path
16072
+ * @this {FormData}
16073
+ *
16074
+ * @returns {boolean} return true to visit the each prop of the value recursively
16075
+ */
16076
+ function defaultVisitor(value, key, path) {
16077
+ let arr = value;
16078
+ if (utils$1$1.isReactNative(formData) && utils$1$1.isReactNativeBlob(value)) {
16079
+ formData.append(renderKey(path, key, dots), convertValue(value));
16080
+ return false;
16081
+ }
16082
+ if (value && !path && typeof value === 'object') {
16083
+ if (utils$1$1.endsWith(key, '{}')) {
16084
+ // eslint-disable-next-line no-param-reassign
16085
+ key = metaTokens ? key : key.slice(0, -2);
16086
+ // eslint-disable-next-line no-param-reassign
16087
+ value = JSON.stringify(value);
16088
+ } else if (utils$1$1.isArray(value) && isFlatArray(value) || (utils$1$1.isFileList(value) || utils$1$1.endsWith(key, '[]')) && (arr = utils$1$1.toArray(value))) {
16089
+ // eslint-disable-next-line no-param-reassign
16090
+ key = removeBrackets(key);
16091
+ arr.forEach(function each(el, index) {
16092
+ !(utils$1$1.isUndefined(el) || el === null) && formData.append(
16093
+ // eslint-disable-next-line no-nested-ternary
16094
+ indexes === true ? renderKey([key], index, dots) : indexes === null ? key : key + '[]', convertValue(el));
16095
+ });
16096
+ return false;
16097
+ }
16098
+ }
16099
+ if (isVisitable(value)) {
16100
+ return true;
16101
+ }
16102
+ formData.append(renderKey(path, key, dots), convertValue(value));
16103
+ return false;
16104
+ }
16105
+ const stack = [];
16106
+ const exposedHelpers = Object.assign(predicates, {
16107
+ defaultVisitor,
16108
+ convertValue,
16109
+ isVisitable
16110
+ });
16111
+ function build(value, path, depth = 0) {
16112
+ if (utils$1$1.isUndefined(value)) return;
16113
+ if (depth > maxDepth) {
16114
+ throw new AxiosError('Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth, AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED);
16115
+ }
16116
+ if (stack.indexOf(value) !== -1) {
16117
+ throw Error('Circular reference detected in ' + path.join('.'));
16118
+ }
16119
+ stack.push(value);
16120
+ utils$1$1.forEach(value, function each(el, key) {
16121
+ const result = !(utils$1$1.isUndefined(el) || el === null) && visitor.call(formData, el, utils$1$1.isString(key) ? key.trim() : key, path, exposedHelpers);
16122
+ if (result === true) {
16123
+ build(el, path ? path.concat(key) : [key], depth + 1);
16124
+ }
16125
+ });
16126
+ stack.pop();
16127
+ }
16128
+ if (!utils$1$1.isObject(obj)) {
16129
+ throw new TypeError('data must be an object');
16130
+ }
16131
+ build(obj);
16132
+ return formData;
16133
+ }
16134
+
16135
+ /**
16136
+ * It encodes a string by replacing all characters that are not in the unreserved set with
16137
+ * their percent-encoded equivalents
16138
+ *
16139
+ * @param {string} str - The string to encode.
16140
+ *
16141
+ * @returns {string} The encoded string.
16142
+ */
16143
+ function encode$1(str) {
16144
+ const charMap = {
16145
+ '!': '%21',
16146
+ "'": '%27',
16147
+ '(': '%28',
16148
+ ')': '%29',
16149
+ '~': '%7E',
16150
+ '%20': '+'
16151
+ };
16152
+ return encodeURIComponent(str).replace(/[!'()~]|%20/g, function replacer(match) {
16153
+ return charMap[match];
16154
+ });
16155
+ }
16156
+
16157
+ /**
16158
+ * It takes a params object and converts it to a FormData object
16159
+ *
16160
+ * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
16161
+ * @param {Object<string, any>} options - The options object passed to the Axios constructor.
16162
+ *
16163
+ * @returns {void}
16164
+ */
16165
+ function AxiosURLSearchParams(params, options) {
16166
+ this._pairs = [];
16167
+ params && toFormData(params, this, options);
16168
+ }
16169
+ const prototype = AxiosURLSearchParams.prototype;
16170
+ prototype.append = function append(name, value) {
16171
+ this._pairs.push([name, value]);
16172
+ };
16173
+ prototype.toString = function toString(encoder) {
16174
+ const _encode = encoder ? function (value) {
16175
+ return encoder.call(this, value, encode$1);
16176
+ } : encode$1;
16177
+ return this._pairs.map(function each(pair) {
16178
+ return _encode(pair[0]) + '=' + _encode(pair[1]);
16179
+ }, '').join('&');
16180
+ };
16181
+
16182
+ /**
16183
+ * It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
16184
+ * their plain counterparts (`:`, `$`, `,`, `+`).
16185
+ *
16186
+ * @param {string} val The value to be encoded.
16187
+ *
16188
+ * @returns {string} The encoded value.
16189
+ */
16190
+ function encode$2(val) {
16191
+ return encodeURIComponent(val).replace(/%3A/gi, ':').replace(/%24/g, '$').replace(/%2C/gi, ',').replace(/%20/g, '+');
16192
+ }
16193
+
16194
+ /**
16195
+ * Build a URL by appending params to the end
16196
+ *
16197
+ * @param {string} url The base of the url (e.g., http://www.google.com)
16198
+ * @param {object} [params] The params to be appended
16199
+ * @param {?(object|Function)} options
16200
+ *
16201
+ * @returns {string} The formatted url
16202
+ */
16203
+ function buildURL(url, params, options) {
16204
+ if (!params) {
16205
+ return url;
16206
+ }
16207
+ const _encode = options && options.encode || encode$2;
16208
+ const _options = utils$1$1.isFunction(options) ? {
16209
+ serialize: options
16210
+ } : options;
16211
+ const serializeFn = _options && _options.serialize;
16212
+ let serializedParams;
16213
+ if (serializeFn) {
16214
+ serializedParams = serializeFn(params, _options);
16215
+ } else {
16216
+ serializedParams = utils$1$1.isURLSearchParams(params) ? params.toString() : new AxiosURLSearchParams(params, _options).toString(_encode);
16217
+ }
16218
+ if (serializedParams) {
16219
+ const hashmarkIndex = url.indexOf('#');
16220
+ if (hashmarkIndex !== -1) {
16221
+ url = url.slice(0, hashmarkIndex);
16222
+ }
16223
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
16224
+ }
16225
+ return url;
16226
+ }
16227
+ class InterceptorManager {
16228
+ constructor() {
16229
+ this.handlers = [];
16230
+ }
16231
+
16232
+ /**
16233
+ * Add a new interceptor to the stack
16234
+ *
16235
+ * @param {Function} fulfilled The function to handle `then` for a `Promise`
16236
+ * @param {Function} rejected The function to handle `reject` for a `Promise`
16237
+ * @param {Object} options The options for the interceptor, synchronous and runWhen
16238
+ *
16239
+ * @return {Number} An ID used to remove interceptor later
16240
+ */
16241
+ use(fulfilled, rejected, options) {
16242
+ this.handlers.push({
16243
+ fulfilled,
16244
+ rejected,
16245
+ synchronous: options ? options.synchronous : false,
16246
+ runWhen: options ? options.runWhen : null
16247
+ });
16248
+ return this.handlers.length - 1;
16249
+ }
16250
+
16251
+ /**
16252
+ * Remove an interceptor from the stack
16253
+ *
16254
+ * @param {Number} id The ID that was returned by `use`
16255
+ *
16256
+ * @returns {void}
16257
+ */
16258
+ eject(id) {
16259
+ if (this.handlers[id]) {
16260
+ this.handlers[id] = null;
16261
+ }
16262
+ }
16263
+
16264
+ /**
16265
+ * Clear all interceptors from the stack
16266
+ *
16267
+ * @returns {void}
16268
+ */
16269
+ clear() {
16270
+ if (this.handlers) {
16271
+ this.handlers = [];
15869
16272
  }
15870
16273
  }
15871
16274
 
@@ -16035,7 +16438,7 @@ function formDataToJSON(formData) {
16035
16438
  name = !name && utils$1$1.isArray(target) ? target.length : name;
16036
16439
  if (isLast) {
16037
16440
  if (utils$1$1.hasOwnProp(target, name)) {
16038
- target[name] = [target[name], value];
16441
+ target[name] = utils$1$1.isArray(target[name]) ? target[name].concat(value) : [target[name], value];
16039
16442
  } else {
16040
16443
  target[name] = value;
16041
16444
  }
@@ -16059,421 +16462,125 @@ function formDataToJSON(formData) {
16059
16462
  }
16060
16463
  return null;
16061
16464
  }
16465
+ const own = (obj, key) => obj != null && utils$1$1.hasOwnProp(obj, key) ? obj[key] : undefined;
16062
16466
 
16063
16467
  /**
16064
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
16065
- * of the input
16066
- *
16067
- * @param {any} rawValue - The value to be stringified.
16068
- * @param {Function} parser - A function that parses a string into a JavaScript object.
16069
- * @param {Function} encoder - A function that takes a value and returns a string.
16070
- *
16071
- * @returns {string} A stringified version of the rawValue.
16072
- */
16073
- function stringifySafely(rawValue, parser, encoder) {
16074
- if (utils$1$1.isString(rawValue)) {
16075
- try {
16076
- (parser || JSON.parse)(rawValue);
16077
- return utils$1$1.trim(rawValue);
16078
- } catch (e) {
16079
- if (e.name !== 'SyntaxError') {
16080
- throw e;
16081
- }
16082
- }
16083
- }
16084
- return (encoder || JSON.stringify)(rawValue);
16085
- }
16086
- const defaults$2 = {
16087
- transitional: transitionalDefaults,
16088
- adapter: ['xhr', 'http', 'fetch'],
16089
- transformRequest: [function transformRequest(data, headers) {
16090
- const contentType = headers.getContentType() || '';
16091
- const hasJSONContentType = contentType.indexOf('application/json') > -1;
16092
- const isObjectPayload = utils$1$1.isObject(data);
16093
- if (isObjectPayload && utils$1$1.isHTMLForm(data)) {
16094
- data = new FormData(data);
16095
- }
16096
- const isFormData = utils$1$1.isFormData(data);
16097
- if (isFormData) {
16098
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
16099
- }
16100
- if (utils$1$1.isArrayBuffer(data) || utils$1$1.isBuffer(data) || utils$1$1.isStream(data) || utils$1$1.isFile(data) || utils$1$1.isBlob(data) || utils$1$1.isReadableStream(data)) {
16101
- return data;
16102
- }
16103
- if (utils$1$1.isArrayBufferView(data)) {
16104
- return data.buffer;
16105
- }
16106
- if (utils$1$1.isURLSearchParams(data)) {
16107
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
16108
- return data.toString();
16109
- }
16110
- let isFileList;
16111
- if (isObjectPayload) {
16112
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
16113
- return toURLEncodedForm(data, this.formSerializer).toString();
16114
- }
16115
- if ((isFileList = utils$1$1.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
16116
- const _FormData = this.env && this.env.FormData;
16117
- return toFormData(isFileList ? {
16118
- 'files[]': data
16119
- } : data, _FormData && new _FormData(), this.formSerializer);
16120
- }
16121
- }
16122
- if (isObjectPayload || hasJSONContentType) {
16123
- headers.setContentType('application/json', false);
16124
- return stringifySafely(data);
16125
- }
16126
- return data;
16127
- }],
16128
- transformResponse: [function transformResponse(data) {
16129
- const transitional = this.transitional || defaults$2.transitional;
16130
- const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
16131
- const JSONRequested = this.responseType === 'json';
16132
- if (utils$1$1.isResponse(data) || utils$1$1.isReadableStream(data)) {
16133
- return data;
16134
- }
16135
- if (data && utils$1$1.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
16136
- const silentJSONParsing = transitional && transitional.silentJSONParsing;
16137
- const strictJSONParsing = !silentJSONParsing && JSONRequested;
16138
- try {
16139
- return JSON.parse(data, this.parseReviver);
16140
- } catch (e) {
16141
- if (strictJSONParsing) {
16142
- if (e.name === 'SyntaxError') {
16143
- throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
16144
- }
16145
- throw e;
16146
- }
16147
- }
16148
- }
16149
- return data;
16150
- }],
16151
- /**
16152
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
16153
- * timeout is not created.
16154
- */
16155
- timeout: 0,
16156
- xsrfCookieName: 'XSRF-TOKEN',
16157
- xsrfHeaderName: 'X-XSRF-TOKEN',
16158
- maxContentLength: -1,
16159
- maxBodyLength: -1,
16160
- env: {
16161
- FormData: platform.classes.FormData,
16162
- Blob: platform.classes.Blob
16163
- },
16164
- validateStatus: function validateStatus(status) {
16165
- return status >= 200 && status < 300;
16166
- },
16167
- headers: {
16168
- common: {
16169
- Accept: 'application/json, text/plain, */*',
16170
- 'Content-Type': undefined
16171
- }
16172
- }
16173
- };
16174
- utils$1$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], method => {
16175
- defaults$2.headers[method] = {};
16176
- });
16177
-
16178
- // RawAxiosHeaders whose duplicates are ignored by node
16179
- // c.f. https://nodejs.org/api/http.html#http_message_headers
16180
- const ignoreDuplicateOf = utils$1$1.toObjectSet(['age', 'authorization', 'content-length', 'content-type', 'etag', 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since', 'last-modified', 'location', 'max-forwards', 'proxy-authorization', 'referer', 'retry-after', 'user-agent']);
16181
-
16182
- /**
16183
- * Parse headers into an object
16184
- *
16185
- * ```
16186
- * Date: Wed, 27 Aug 2014 08:58:49 GMT
16187
- * Content-Type: application/json
16188
- * Connection: keep-alive
16189
- * Transfer-Encoding: chunked
16190
- * ```
16191
- *
16192
- * @param {String} rawHeaders Headers needing to be parsed
16193
- *
16194
- * @returns {Object} Headers parsed into an object
16195
- */
16196
- var parseHeaders = rawHeaders => {
16197
- const parsed = {};
16198
- let key;
16199
- let val;
16200
- let i;
16201
- rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
16202
- i = line.indexOf(':');
16203
- key = line.substring(0, i).trim().toLowerCase();
16204
- val = line.substring(i + 1).trim();
16205
- if (!key || parsed[key] && ignoreDuplicateOf[key]) {
16206
- return;
16207
- }
16208
- if (key === 'set-cookie') {
16209
- if (parsed[key]) {
16210
- parsed[key].push(val);
16211
- } else {
16212
- parsed[key] = [val];
16213
- }
16214
- } else {
16215
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
16216
- }
16217
- });
16218
- return parsed;
16219
- };
16220
- const $internals = Symbol('internals');
16221
- const isValidHeaderValue = value => !/[\r\n]/.test(value);
16222
- function assertValidHeaderValue(value, header) {
16223
- if (value === false || value == null) {
16224
- return;
16225
- }
16226
- if (utils$1$1.isArray(value)) {
16227
- value.forEach(v => assertValidHeaderValue(v, header));
16228
- return;
16229
- }
16230
- if (!isValidHeaderValue(String(value))) {
16231
- throw new Error(`Invalid character in header content ["${header}"]`);
16232
- }
16233
- }
16234
- function normalizeHeader(header) {
16235
- return header && String(header).trim().toLowerCase();
16236
- }
16237
- function stripTrailingCRLF(str) {
16238
- let end = str.length;
16239
- while (end > 0) {
16240
- const charCode = str.charCodeAt(end - 1);
16241
- if (charCode !== 10 && charCode !== 13) {
16242
- break;
16243
- }
16244
- end -= 1;
16245
- }
16246
- return end === str.length ? str : str.slice(0, end);
16247
- }
16248
- function normalizeValue(value) {
16249
- if (value === false || value == null) {
16250
- return value;
16251
- }
16252
- return utils$1$1.isArray(value) ? value.map(normalizeValue) : stripTrailingCRLF(String(value));
16253
- }
16254
- function parseTokens(str) {
16255
- const tokens = Object.create(null);
16256
- const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
16257
- let match;
16258
- while (match = tokensRE.exec(str)) {
16259
- tokens[match[1]] = match[2];
16260
- }
16261
- return tokens;
16262
- }
16263
- const isValidHeaderName = str => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
16264
- function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
16265
- if (utils$1$1.isFunction(filter)) {
16266
- return filter.call(this, value, header);
16267
- }
16268
- if (isHeaderNameFilter) {
16269
- value = header;
16270
- }
16271
- if (!utils$1$1.isString(value)) return;
16272
- if (utils$1$1.isString(filter)) {
16273
- return value.indexOf(filter) !== -1;
16274
- }
16275
- if (utils$1$1.isRegExp(filter)) {
16276
- return filter.test(value);
16277
- }
16278
- }
16279
- function formatHeader(header) {
16280
- return header.trim().toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
16281
- return char.toUpperCase() + str;
16282
- });
16283
- }
16284
- function buildAccessors(obj, header) {
16285
- const accessorName = utils$1$1.toCamelCase(' ' + header);
16286
- ['get', 'set', 'has'].forEach(methodName => {
16287
- Object.defineProperty(obj, methodName + accessorName, {
16288
- value: function (arg1, arg2, arg3) {
16289
- return this[methodName].call(this, header, arg1, arg2, arg3);
16290
- },
16291
- configurable: true
16292
- });
16293
- });
16294
- }
16295
- class AxiosHeaders {
16296
- constructor(headers) {
16297
- headers && this.set(headers);
16298
- }
16299
- set(header, valueOrRewrite, rewrite) {
16300
- const self = this;
16301
- function setHeader(_value, _header, _rewrite) {
16302
- const lHeader = normalizeHeader(_header);
16303
- if (!lHeader) {
16304
- throw new Error('header name must be a non-empty string');
16305
- }
16306
- const key = utils$1$1.findKey(self, lHeader);
16307
- if (!key || self[key] === undefined || _rewrite === true || _rewrite === undefined && self[key] !== false) {
16308
- assertValidHeaderValue(_value, _header);
16309
- self[key || _header] = normalizeValue(_value);
16310
- }
16311
- }
16312
- const setHeaders = (headers, _rewrite) => utils$1$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
16313
- if (utils$1$1.isPlainObject(header) || header instanceof this.constructor) {
16314
- setHeaders(header, valueOrRewrite);
16315
- } else if (utils$1$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
16316
- setHeaders(parseHeaders(header), valueOrRewrite);
16317
- } else if (utils$1$1.isObject(header) && utils$1$1.isIterable(header)) {
16318
- let obj = {},
16319
- dest,
16320
- key;
16321
- for (const entry of header) {
16322
- if (!utils$1$1.isArray(entry)) {
16323
- throw TypeError('Object iterator must return a key-value pair');
16324
- }
16325
- obj[key = entry[0]] = (dest = obj[key]) ? utils$1$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]] : entry[1];
16326
- }
16327
- setHeaders(obj, valueOrRewrite);
16328
- } else {
16329
- header != null && setHeader(valueOrRewrite, header, rewrite);
16330
- }
16331
- return this;
16332
- }
16333
- get(header, parser) {
16334
- header = normalizeHeader(header);
16335
- if (header) {
16336
- const key = utils$1$1.findKey(this, header);
16337
- if (key) {
16338
- const value = this[key];
16339
- if (!parser) {
16340
- return value;
16341
- }
16342
- if (parser === true) {
16343
- return parseTokens(value);
16344
- }
16345
- if (utils$1$1.isFunction(parser)) {
16346
- return parser.call(this, value, key);
16347
- }
16348
- if (utils$1$1.isRegExp(parser)) {
16349
- return parser.exec(value);
16350
- }
16351
- throw new TypeError('parser must be boolean|regexp|function');
16352
- }
16353
- }
16354
- }
16355
- has(header, matcher) {
16356
- header = normalizeHeader(header);
16357
- if (header) {
16358
- const key = utils$1$1.findKey(this, header);
16359
- return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
16360
- }
16361
- return false;
16362
- }
16363
- delete(header, matcher) {
16364
- const self = this;
16365
- let deleted = false;
16366
- function deleteHeader(_header) {
16367
- _header = normalizeHeader(_header);
16368
- if (_header) {
16369
- const key = utils$1$1.findKey(self, _header);
16370
- if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
16371
- delete self[key];
16372
- deleted = true;
16373
- }
16374
- }
16375
- }
16376
- if (utils$1$1.isArray(header)) {
16377
- header.forEach(deleteHeader);
16378
- } else {
16379
- deleteHeader(header);
16380
- }
16381
- return deleted;
16382
- }
16383
- clear(matcher) {
16384
- const keys = Object.keys(this);
16385
- let i = keys.length;
16386
- let deleted = false;
16387
- while (i--) {
16388
- const key = keys[i];
16389
- if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
16390
- delete this[key];
16391
- deleted = true;
16392
- }
16393
- }
16394
- return deleted;
16395
- }
16396
- normalize(format) {
16397
- const self = this;
16398
- const headers = {};
16399
- utils$1$1.forEach(this, (value, header) => {
16400
- const key = utils$1$1.findKey(headers, header);
16401
- if (key) {
16402
- self[key] = normalizeValue(value);
16403
- delete self[header];
16404
- return;
16405
- }
16406
- const normalized = format ? formatHeader(header) : String(header).trim();
16407
- if (normalized !== header) {
16408
- delete self[header];
16409
- }
16410
- self[normalized] = normalizeValue(value);
16411
- headers[normalized] = true;
16412
- });
16413
- return this;
16414
- }
16415
- concat(...targets) {
16416
- return this.constructor.concat(this, ...targets);
16417
- }
16418
- toJSON(asStrings) {
16419
- const obj = Object.create(null);
16420
- utils$1$1.forEach(this, (value, header) => {
16421
- value != null && value !== false && (obj[header] = asStrings && utils$1$1.isArray(value) ? value.join(', ') : value);
16422
- });
16423
- return obj;
16424
- }
16425
- [Symbol.iterator]() {
16426
- return Object.entries(this.toJSON())[Symbol.iterator]();
16427
- }
16428
- toString() {
16429
- return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
16430
- }
16431
- getSetCookie() {
16432
- return this.get('set-cookie') || [];
16433
- }
16434
- get [Symbol.toStringTag]() {
16435
- return 'AxiosHeaders';
16436
- }
16437
- static from(thing) {
16438
- return thing instanceof this ? thing : new this(thing);
16439
- }
16440
- static concat(first, ...targets) {
16441
- const computed = new this(first);
16442
- targets.forEach(target => computed.set(target));
16443
- return computed;
16444
- }
16445
- static accessor(header) {
16446
- const internals = this[$internals] = this[$internals] = {
16447
- accessors: {}
16448
- };
16449
- const accessors = internals.accessors;
16450
- const prototype = this.prototype;
16451
- function defineAccessor(_header) {
16452
- const lHeader = normalizeHeader(_header);
16453
- if (!accessors[lHeader]) {
16454
- buildAccessors(prototype, _header);
16455
- accessors[lHeader] = true;
16468
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
16469
+ * of the input
16470
+ *
16471
+ * @param {any} rawValue - The value to be stringified.
16472
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
16473
+ * @param {Function} encoder - A function that takes a value and returns a string.
16474
+ *
16475
+ * @returns {string} A stringified version of the rawValue.
16476
+ */
16477
+ function stringifySafely(rawValue, parser, encoder) {
16478
+ if (utils$1$1.isString(rawValue)) {
16479
+ try {
16480
+ (parser || JSON.parse)(rawValue);
16481
+ return utils$1$1.trim(rawValue);
16482
+ } catch (e) {
16483
+ if (e.name !== 'SyntaxError') {
16484
+ throw e;
16456
16485
  }
16457
16486
  }
16458
- utils$1$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
16459
- return this;
16460
16487
  }
16488
+ return (encoder || JSON.stringify)(rawValue);
16461
16489
  }
16462
- AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
16463
-
16464
- // reserved names hotfix
16465
- utils$1$1.reduceDescriptors(AxiosHeaders.prototype, ({
16466
- value
16467
- }, key) => {
16468
- let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
16469
- return {
16470
- get: () => value,
16471
- set(headerValue) {
16472
- this[mapped] = headerValue;
16490
+ const defaults$2 = {
16491
+ transitional: transitionalDefaults,
16492
+ adapter: ['xhr', 'http', 'fetch'],
16493
+ transformRequest: [function transformRequest(data, headers) {
16494
+ const contentType = headers.getContentType() || '';
16495
+ const hasJSONContentType = contentType.indexOf('application/json') > -1;
16496
+ const isObjectPayload = utils$1$1.isObject(data);
16497
+ if (isObjectPayload && utils$1$1.isHTMLForm(data)) {
16498
+ data = new FormData(data);
16473
16499
  }
16474
- };
16500
+ const isFormData = utils$1$1.isFormData(data);
16501
+ if (isFormData) {
16502
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
16503
+ }
16504
+ if (utils$1$1.isArrayBuffer(data) || utils$1$1.isBuffer(data) || utils$1$1.isStream(data) || utils$1$1.isFile(data) || utils$1$1.isBlob(data) || utils$1$1.isReadableStream(data)) {
16505
+ return data;
16506
+ }
16507
+ if (utils$1$1.isArrayBufferView(data)) {
16508
+ return data.buffer;
16509
+ }
16510
+ if (utils$1$1.isURLSearchParams(data)) {
16511
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
16512
+ return data.toString();
16513
+ }
16514
+ let isFileList;
16515
+ if (isObjectPayload) {
16516
+ const formSerializer = own(this, 'formSerializer');
16517
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
16518
+ return toURLEncodedForm(data, formSerializer).toString();
16519
+ }
16520
+ if ((isFileList = utils$1$1.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
16521
+ const env = own(this, 'env');
16522
+ const _FormData = env && env.FormData;
16523
+ return toFormData(isFileList ? {
16524
+ 'files[]': data
16525
+ } : data, _FormData && new _FormData(), formSerializer);
16526
+ }
16527
+ }
16528
+ if (isObjectPayload || hasJSONContentType) {
16529
+ headers.setContentType('application/json', false);
16530
+ return stringifySafely(data);
16531
+ }
16532
+ return data;
16533
+ }],
16534
+ transformResponse: [function transformResponse(data) {
16535
+ const transitional = own(this, 'transitional') || defaults$2.transitional;
16536
+ const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
16537
+ const responseType = own(this, 'responseType');
16538
+ const JSONRequested = responseType === 'json';
16539
+ if (utils$1$1.isResponse(data) || utils$1$1.isReadableStream(data)) {
16540
+ return data;
16541
+ }
16542
+ if (data && utils$1$1.isString(data) && (forcedJSONParsing && !responseType || JSONRequested)) {
16543
+ const silentJSONParsing = transitional && transitional.silentJSONParsing;
16544
+ const strictJSONParsing = !silentJSONParsing && JSONRequested;
16545
+ try {
16546
+ return JSON.parse(data, own(this, 'parseReviver'));
16547
+ } catch (e) {
16548
+ if (strictJSONParsing) {
16549
+ if (e.name === 'SyntaxError') {
16550
+ throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, own(this, 'response'));
16551
+ }
16552
+ throw e;
16553
+ }
16554
+ }
16555
+ }
16556
+ return data;
16557
+ }],
16558
+ /**
16559
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
16560
+ * timeout is not created.
16561
+ */
16562
+ timeout: 0,
16563
+ xsrfCookieName: 'XSRF-TOKEN',
16564
+ xsrfHeaderName: 'X-XSRF-TOKEN',
16565
+ maxContentLength: -1,
16566
+ maxBodyLength: -1,
16567
+ env: {
16568
+ FormData: platform.classes.FormData,
16569
+ Blob: platform.classes.Blob
16570
+ },
16571
+ validateStatus: function validateStatus(status) {
16572
+ return status >= 200 && status < 300;
16573
+ },
16574
+ headers: {
16575
+ common: {
16576
+ Accept: 'application/json, text/plain, */*',
16577
+ 'Content-Type': undefined
16578
+ }
16579
+ }
16580
+ };
16581
+ utils$1$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'query'], method => {
16582
+ defaults$2.headers[method] = {};
16475
16583
  });
16476
- utils$1$1.freezeMethods(AxiosHeaders);
16477
16584
 
16478
16585
  /**
16479
16586
  * Transform the data for a request or a response
@@ -16528,7 +16635,7 @@ function settle(resolve, reject, response) {
16528
16635
  if (!response.status || !validateStatus || validateStatus(response.status)) {
16529
16636
  resolve(response);
16530
16637
  } else {
16531
- reject(new AxiosError('Request failed with status code ' + response.status, [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4], response.config, response.request, response));
16638
+ reject(new AxiosError('Request failed with status code ' + response.status, response.status >= 400 && response.status < 500 ? AxiosError.ERR_BAD_REQUEST : AxiosError.ERR_BAD_RESPONSE, response.config, response.request, response));
16532
16639
  }
16533
16640
  }
16534
16641
 
@@ -16573,7 +16680,7 @@ function combineURLs(baseURL, relativeURL) {
16573
16680
  */
16574
16681
  function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
16575
16682
  let isRelativeUrl = !isAbsoluteURL(requestedURL);
16576
- if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
16683
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
16577
16684
  return combineURLs(baseURL, requestedURL);
16578
16685
  }
16579
16686
  return requestedURL;
@@ -16673,9 +16780,9 @@ function shouldProxy(hostname, port) {
16673
16780
  function getEnv(key) {
16674
16781
  return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
16675
16782
  }
16676
- const VERSION = "1.15.0";
16783
+ const VERSION = "1.16.0";
16677
16784
  function parseProtocol(url) {
16678
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
16785
+ const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
16679
16786
  return match && match[1] || '';
16680
16787
  }
16681
16788
  const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
@@ -16864,7 +16971,8 @@ class FormDataPart {
16864
16971
  if (isStringValue) {
16865
16972
  value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
16866
16973
  } else {
16867
- headers += `Content-Type: ${value.type || 'application/octet-stream'}${CRLF}`;
16974
+ const safeType = String(value.type || 'application/octet-stream').replace(/[\r\n]/g, '');
16975
+ headers += `Content-Type: ${safeType}${CRLF}`;
16868
16976
  }
16869
16977
  this.headers = textEncoder.encode(headers + CRLF);
16870
16978
  this.contentLength = isStringValue ? value.byteLength : value.size;
@@ -16905,7 +17013,7 @@ const formDataToStream = (form, headersHandler, options) => {
16905
17013
  throw TypeError('FormData instance required');
16906
17014
  }
16907
17015
  if (boundary.length < 1 || boundary.length > 70) {
16908
- throw Error('boundary must be 10-70 characters long');
17016
+ throw Error('boundary must be 1-70 characters long');
16909
17017
  }
16910
17018
  const boundaryBytes = textEncoder.encode('--' + boundary + CRLF);
16911
17019
  const footerBytes = textEncoder.encode('--' + boundary + '--' + CRLF);
@@ -16965,6 +17073,47 @@ const callbackify = (fn, reducer) => {
16965
17073
  }, cb);
16966
17074
  } : fn;
16967
17075
  };
17076
+ const LOOPBACK_HOSTNAMES = new Set(['localhost']);
17077
+ const isIPv4Loopback = host => {
17078
+ const parts = host.split('.');
17079
+ if (parts.length !== 4) return false;
17080
+ if (parts[0] !== '127') return false;
17081
+ return parts.every(p => /^\d+$/.test(p) && Number(p) >= 0 && Number(p) <= 255);
17082
+ };
17083
+ const isIPv6Loopback = host => {
17084
+ // Collapse all-zero groups: any form of ::1 / 0:0:...:0:1
17085
+ // First, strip any leading "::" by normalising with Set lookup of common forms,
17086
+ // then fall back to structural check.
17087
+ if (host === '::1') return true;
17088
+
17089
+ // Check IPv4-mapped IPv6 loopback: ::ffff:<v4-loopback> or ::ffff:<hex-v4-loopback>
17090
+ // Node's URL parser normalises ::ffff:127.0.0.1 → ::ffff:7f00:1
17091
+ const v4MappedDotted = host.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
17092
+ if (v4MappedDotted) return isIPv4Loopback(v4MappedDotted[1]);
17093
+ const v4MappedHex = host.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
17094
+ if (v4MappedHex) {
17095
+ const high = parseInt(v4MappedHex[1], 16);
17096
+ // High 16 bits must start with 127 (0x7f) — i.e. 0x7f00..0x7fff
17097
+ return high >= 0x7f00 && high <= 0x7fff;
17098
+ }
17099
+
17100
+ // Full-form ::1 variants: any number of zero groups followed by trailing 1
17101
+ // e.g. 0:0:0:0:0:0:0:1, 0000:...:0001
17102
+ const groups = host.split(':');
17103
+ if (groups.length === 8) {
17104
+ for (let i = 0; i < 7; i++) {
17105
+ if (!/^0+$/.test(groups[i])) return false;
17106
+ }
17107
+ return /^0*1$/.test(groups[7]);
17108
+ }
17109
+ return false;
17110
+ };
17111
+ const isLoopback = host => {
17112
+ if (!host) return false;
17113
+ if (LOOPBACK_HOSTNAMES.has(host)) return true;
17114
+ if (isIPv4Loopback(host)) return true;
17115
+ return isIPv6Loopback(host);
17116
+ };
16968
17117
  const DEFAULT_PORTS = {
16969
17118
  http: 80,
16970
17119
  https: 443,
@@ -16994,6 +17143,27 @@ const parseNoProxyEntry = entry => {
16994
17143
  }
16995
17144
  return [entryHost, entryPort];
16996
17145
  };
17146
+
17147
+ // Convert IPv4-mapped IPv6 (::ffff:0:0/96 prefix) to IPv4 dotted form so both
17148
+ // sides of a NO_PROXY comparison see the same canonical address. Without this,
17149
+ // `NO_PROXY=192.168.1.5` would not match a request to `http://[::ffff:192.168.1.5]/`
17150
+ // (Node's URL parser normalises that to `[::ffff:c0a8:105]`), and vice-versa,
17151
+ // allowing the proxy-bypass policy to be circumvented by using the alternate
17152
+ // representation. Returns the input unchanged when not IPv4-mapped.
17153
+ const IPV4_MAPPED_DOTTED_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:(\d+\.\d+\.\d+\.\d+)$/i;
17154
+ const IPV4_MAPPED_HEX_RE = /^(?:::|(?:0{1,4}:){1,4}:|(?:0{1,4}:){5})ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i;
17155
+ const unmapIPv4MappedIPv6 = host => {
17156
+ if (typeof host !== 'string' || host.indexOf(':') === -1) return host;
17157
+ const dotted = host.match(IPV4_MAPPED_DOTTED_RE);
17158
+ if (dotted) return dotted[1];
17159
+ const hex = host.match(IPV4_MAPPED_HEX_RE);
17160
+ if (hex) {
17161
+ const high = parseInt(hex[1], 16);
17162
+ const low = parseInt(hex[2], 16);
17163
+ return `${high >> 8}.${high & 0xff}.${low >> 8}.${low & 0xff}`;
17164
+ }
17165
+ return host;
17166
+ };
16997
17167
  const normalizeNoProxyHost = hostname => {
16998
17168
  if (!hostname) {
16999
17169
  return hostname;
@@ -17001,7 +17171,7 @@ const normalizeNoProxyHost = hostname => {
17001
17171
  if (hostname.charAt(0) === '[' && hostname.charAt(hostname.length - 1) === ']') {
17002
17172
  hostname = hostname.slice(1, -1);
17003
17173
  }
17004
- return hostname.replace(/\.+$/, '');
17174
+ return unmapIPv4MappedIPv6(hostname.replace(/\.+$/, ''));
17005
17175
  };
17006
17176
  function shouldBypassProxy(location) {
17007
17177
  let parsed;
@@ -17037,7 +17207,7 @@ function shouldBypassProxy(location) {
17037
17207
  if (entryHost.charAt(0) === '.') {
17038
17208
  return hostname.endsWith(entryHost);
17039
17209
  }
17040
- return hostname === entryHost;
17210
+ return hostname === entryHost || isLoopback(hostname) && isLoopback(entryHost);
17041
17211
  });
17042
17212
  }
17043
17213
 
@@ -17123,19 +17293,19 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
17123
17293
  let bytesNotified = 0;
17124
17294
  const _speedometer = speedometer(50, 250);
17125
17295
  return throttle(e => {
17126
- const loaded = e.loaded;
17296
+ const rawLoaded = e.loaded;
17127
17297
  const total = e.lengthComputable ? e.total : undefined;
17128
- const progressBytes = loaded - bytesNotified;
17298
+ const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
17299
+ const progressBytes = Math.max(0, loaded - bytesNotified);
17129
17300
  const rate = _speedometer(progressBytes);
17130
- const inRange = loaded <= total;
17131
- bytesNotified = loaded;
17301
+ bytesNotified = Math.max(bytesNotified, loaded);
17132
17302
  const data = {
17133
17303
  loaded,
17134
17304
  total,
17135
17305
  progress: total ? loaded / total : undefined,
17136
17306
  bytes: progressBytes,
17137
17307
  rate: rate ? rate : undefined,
17138
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
17308
+ estimated: rate && total ? (total - loaded) / rate : undefined,
17139
17309
  event: e,
17140
17310
  lengthComputable: total != null,
17141
17311
  [isDownloadStream ? 'download' : 'upload']: true
@@ -17213,7 +17383,34 @@ function estimateDataURLDecodedBytes(url) {
17213
17383
  const bytes = groups * 3 - (pad || 0);
17214
17384
  return bytes > 0 ? bytes : 0;
17215
17385
  }
17216
- return Buffer.byteLength(body, 'utf8');
17386
+ if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
17387
+ return Buffer.byteLength(body, 'utf8');
17388
+ }
17389
+
17390
+ // Compute UTF-8 byte length directly from UTF-16 code units without allocating
17391
+ // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
17392
+ // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit
17393
+ // but 3 UTF-8 bytes).
17394
+ let bytes = 0;
17395
+ for (let i = 0, len = body.length; i < len; i++) {
17396
+ const c = body.charCodeAt(i);
17397
+ if (c < 0x80) {
17398
+ bytes += 1;
17399
+ } else if (c < 0x800) {
17400
+ bytes += 2;
17401
+ } else if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {
17402
+ const next = body.charCodeAt(i + 1);
17403
+ if (next >= 0xdc00 && next <= 0xdfff) {
17404
+ bytes += 4;
17405
+ i++;
17406
+ } else {
17407
+ bytes += 3;
17408
+ }
17409
+ } else {
17410
+ bytes += 3;
17411
+ }
17412
+ }
17413
+ return bytes;
17217
17414
  }
17218
17415
  const zlibOptions = {
17219
17416
  flush: zlib.constants.Z_SYNC_FLUSH,
@@ -17229,9 +17426,41 @@ const {
17229
17426
  https: httpsFollow
17230
17427
  } = followRedirects;
17231
17428
  const isHttps = /https:?/;
17429
+ const FORM_DATA_CONTENT_HEADERS$1 = ['content-type', 'content-length'];
17430
+ function setFormDataHeaders$1(headers, formHeaders, policy) {
17431
+ if (policy !== 'content-only') {
17432
+ headers.set(formHeaders);
17433
+ return;
17434
+ }
17435
+ Object.entries(formHeaders).forEach(([key, val]) => {
17436
+ if (FORM_DATA_CONTENT_HEADERS$1.includes(key.toLowerCase())) {
17437
+ headers.set(key, val);
17438
+ }
17439
+ });
17440
+ }
17441
+
17442
+ // Symbols used to bind a single 'error' listener to a pooled socket and track
17443
+ // the request currently owning that socket across keep-alive reuse (issue #10780).
17444
+ const kAxiosSocketListener = Symbol('axios.http.socketListener');
17445
+ const kAxiosCurrentReq = Symbol('axios.http.currentReq');
17232
17446
  const supportedProtocols = platform.protocols.map(protocol => {
17233
17447
  return protocol + ':';
17234
17448
  });
17449
+
17450
+ // Node's WHATWG URL parser returns `username` and `password` percent-encoded.
17451
+ // Decode before composing the `auth` option so credentials such as
17452
+ // `my%40email.com:pass` are sent as `my@email.com:pass`. Falls back to the
17453
+ // original value for malformed input so a bad encoding never throws.
17454
+ const decodeURIComponentSafe = value => {
17455
+ if (!utils$1$1.isString(value)) {
17456
+ return value;
17457
+ }
17458
+ try {
17459
+ return decodeURIComponent(value);
17460
+ } catch (error) {
17461
+ return value;
17462
+ }
17463
+ };
17235
17464
  const flushOnFinish = (stream, [throttled, flush]) => {
17236
17465
  stream.on('end', flush).on('error', flush);
17237
17466
  return throttled;
@@ -17319,12 +17548,12 @@ const http2Sessions = new Http2Sessions();
17319
17548
  *
17320
17549
  * @returns {Object<string, any>}
17321
17550
  */
17322
- function dispatchBeforeRedirect(options, responseDetails) {
17551
+ function dispatchBeforeRedirect(options, responseDetails, requestDetails) {
17323
17552
  if (options.beforeRedirects.proxy) {
17324
17553
  options.beforeRedirects.proxy(options);
17325
17554
  }
17326
17555
  if (options.beforeRedirects.config) {
17327
- options.beforeRedirects.config(options, responseDetails);
17556
+ options.beforeRedirects.config(options, responseDetails, requestDetails);
17328
17557
  }
17329
17558
  }
17330
17559
 
@@ -17337,7 +17566,7 @@ function dispatchBeforeRedirect(options, responseDetails) {
17337
17566
  *
17338
17567
  * @returns {http.ClientRequestArgs}
17339
17568
  */
17340
- function setProxy(options, configProxy, location) {
17569
+ function setProxy(options, configProxy, location, isRedirect) {
17341
17570
  let proxy = configProxy;
17342
17571
  if (!proxy && proxy !== false) {
17343
17572
  const proxyUrl = getProxyForUrl(location);
@@ -17347,39 +17576,80 @@ function setProxy(options, configProxy, location) {
17347
17576
  }
17348
17577
  }
17349
17578
  }
17579
+ // On redirect re-invocation, strip any stale Proxy-Authorization header carried
17580
+ // over from the prior request (e.g. new target no longer uses a proxy, or uses
17581
+ // a different proxy). Skip on the initial request so user-supplied headers are
17582
+ // preserved. Header names are case-insensitive, so remove every case variant.
17583
+ if (isRedirect && options.headers) {
17584
+ for (const name of Object.keys(options.headers)) {
17585
+ if (name.toLowerCase() === 'proxy-authorization') {
17586
+ delete options.headers[name];
17587
+ }
17588
+ }
17589
+ }
17350
17590
  if (proxy) {
17591
+ // Read proxy fields without traversing the prototype chain. URL instances expose
17592
+ // username/password/hostname/host/port/protocol via getters on URL.prototype (so
17593
+ // direct reads are shielded), but plain object proxies — and the `auth` field
17594
+ // (which URL does not expose) — must be guarded so a polluted Object.prototype
17595
+ // (e.g. Object.prototype.auth = { username, password }) cannot inject
17596
+ // attacker-controlled credentials into the Proxy-Authorization header or
17597
+ // redirect proxying to an attacker-controlled host.
17598
+ const isProxyURL = proxy instanceof URL;
17599
+ const readProxyField = key => isProxyURL || utils$1$1.hasOwnProp(proxy, key) ? proxy[key] : undefined;
17600
+ const proxyUsername = readProxyField('username');
17601
+ const proxyPassword = readProxyField('password');
17602
+ let proxyAuth = utils$1$1.hasOwnProp(proxy, 'auth') ? proxy.auth : undefined;
17603
+
17351
17604
  // Basic proxy authorization
17352
- if (proxy.username) {
17353
- proxy.auth = (proxy.username || '') + ':' + (proxy.password || '');
17354
- }
17355
- if (proxy.auth) {
17356
- // Support proxy auth object form
17357
- const validProxyAuth = Boolean(proxy.auth.username || proxy.auth.password);
17605
+ if (proxyUsername) {
17606
+ proxyAuth = (proxyUsername || '') + ':' + (proxyPassword || '');
17607
+ }
17608
+ if (proxyAuth) {
17609
+ // Support proxy auth object form. Read sub-fields via own-prop checks so a
17610
+ // plain object inheriting from polluted Object.prototype cannot leak creds.
17611
+ const authIsObject = typeof proxyAuth === 'object';
17612
+ const authUsername = authIsObject && utils$1$1.hasOwnProp(proxyAuth, 'username') ? proxyAuth.username : undefined;
17613
+ const authPassword = authIsObject && utils$1$1.hasOwnProp(proxyAuth, 'password') ? proxyAuth.password : undefined;
17614
+ const validProxyAuth = Boolean(authUsername || authPassword);
17358
17615
  if (validProxyAuth) {
17359
- proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || '');
17360
- } else if (typeof proxy.auth === 'object') {
17616
+ proxyAuth = (authUsername || '') + ':' + (authPassword || '');
17617
+ } else if (authIsObject) {
17361
17618
  throw new AxiosError('Invalid proxy authorization', AxiosError.ERR_BAD_OPTION, {
17362
17619
  proxy
17363
17620
  });
17364
17621
  }
17365
- const base64 = Buffer.from(proxy.auth, 'utf8').toString('base64');
17622
+ const base64 = Buffer.from(proxyAuth, 'utf8').toString('base64');
17366
17623
  options.headers['Proxy-Authorization'] = 'Basic ' + base64;
17367
17624
  }
17368
- options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
17369
- const proxyHost = proxy.hostname || proxy.host;
17625
+
17626
+ // Preserve a user-supplied Host header (case-insensitive) so callers can override
17627
+ // the value forwarded to the proxy; otherwise default to the request URL's host.
17628
+ let hasUserHostHeader = false;
17629
+ for (const name of Object.keys(options.headers)) {
17630
+ if (name.toLowerCase() === 'host') {
17631
+ hasUserHostHeader = true;
17632
+ break;
17633
+ }
17634
+ }
17635
+ if (!hasUserHostHeader) {
17636
+ options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
17637
+ }
17638
+ const proxyHost = readProxyField('hostname') || readProxyField('host');
17370
17639
  options.hostname = proxyHost;
17371
17640
  // Replace 'host' since options is not a URL object
17372
17641
  options.host = proxyHost;
17373
- options.port = proxy.port;
17642
+ options.port = readProxyField('port');
17374
17643
  options.path = location;
17375
- if (proxy.protocol) {
17376
- options.protocol = proxy.protocol.includes(':') ? proxy.protocol : `${proxy.protocol}:`;
17644
+ const proxyProtocol = readProxyField('protocol');
17645
+ if (proxyProtocol) {
17646
+ options.protocol = proxyProtocol.includes(':') ? proxyProtocol : `${proxyProtocol}:`;
17377
17647
  }
17378
17648
  }
17379
17649
  options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
17380
17650
  // Configure proxy for redirected request, passing the original config proxy to apply
17381
17651
  // the exact same logic as if the redirected request was performed by axios directly.
17382
- setProxy(redirectOptions, configProxy, redirectOptions.href);
17652
+ setProxy(redirectOptions, configProxy, redirectOptions.href, true);
17383
17653
  };
17384
17654
  }
17385
17655
  const isHttpAdapterSupported = typeof process !== 'undefined' && utils$1$1.kindOf(process) === 'process';
@@ -17462,21 +17732,20 @@ const http2Transport = {
17462
17732
  /*eslint consistent-return:0*/
17463
17733
  var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17464
17734
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
17465
- let {
17466
- data,
17467
- lookup,
17468
- family,
17469
- httpVersion = 1,
17470
- http2Options
17471
- } = config;
17472
- const {
17473
- responseType,
17474
- responseEncoding
17475
- } = config;
17735
+ const own = key => utils$1$1.hasOwnProp(config, key) ? config[key] : undefined;
17736
+ let data = own('data');
17737
+ let lookup = own('lookup');
17738
+ let family = own('family');
17739
+ let httpVersion = own('httpVersion');
17740
+ if (httpVersion === undefined) httpVersion = 1;
17741
+ let http2Options = own('http2Options');
17742
+ const responseType = own('responseType');
17743
+ const responseEncoding = own('responseEncoding');
17476
17744
  const method = config.method.toUpperCase();
17477
17745
  let isDone;
17478
17746
  let rejected = false;
17479
17747
  let req;
17748
+ let connectPhaseTimer;
17480
17749
  httpVersion = +httpVersion;
17481
17750
  if (Number.isNaN(httpVersion)) {
17482
17751
  throw TypeError(`Invalid protocol version: '${config.httpVersion}' is not a number`);
@@ -17506,8 +17775,23 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17506
17775
  console.warn('emit error', err);
17507
17776
  }
17508
17777
  }
17778
+ function clearConnectPhaseTimer() {
17779
+ if (connectPhaseTimer) {
17780
+ clearTimeout(connectPhaseTimer);
17781
+ connectPhaseTimer = null;
17782
+ }
17783
+ }
17784
+ function createTimeoutError() {
17785
+ let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
17786
+ const transitional = config.transitional || transitionalDefaults;
17787
+ if (config.timeoutErrorMessage) {
17788
+ timeoutErrorMessage = config.timeoutErrorMessage;
17789
+ }
17790
+ return new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, req);
17791
+ }
17509
17792
  abortEmitter.once('abort', reject);
17510
17793
  const onFinished = () => {
17794
+ clearConnectPhaseTimer();
17511
17795
  if (config.cancelToken) {
17512
17796
  config.cancelToken.unsubscribe(abort);
17513
17797
  }
@@ -17524,6 +17808,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17524
17808
  }
17525
17809
  onDone((response, isRejected) => {
17526
17810
  isDone = true;
17811
+ clearConnectPhaseTimer();
17527
17812
  if (isRejected) {
17528
17813
  rejected = true;
17529
17814
  onFinished();
@@ -17616,8 +17901,8 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17616
17901
  boundary: userBoundary && userBoundary[1] || undefined
17617
17902
  });
17618
17903
  // support for https://www.npmjs.com/package/form-data api
17619
- } else if (utils$1$1.isFormData(data) && utils$1$1.isFunction(data.getHeaders)) {
17620
- headers.set(data.getHeaders());
17904
+ } else if (utils$1$1.isFormData(data) && utils$1$1.isFunction(data.getHeaders) && data.getHeaders !== Object.prototype.getHeaders) {
17905
+ setFormDataHeaders$1(headers, data.getHeaders(), own('formDataHeaderPolicy'));
17621
17906
  if (!headers.hasContentLength()) {
17622
17907
  try {
17623
17908
  const knownLength = await util.promisify(data.getLength).call(data);
@@ -17665,20 +17950,21 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17665
17950
 
17666
17951
  // HTTP basic authentication
17667
17952
  let auth = undefined;
17668
- if (config.auth) {
17669
- const username = config.auth.username || '';
17670
- const password = config.auth.password || '';
17953
+ const configAuth = own('auth');
17954
+ if (configAuth) {
17955
+ const username = configAuth.username || '';
17956
+ const password = configAuth.password || '';
17671
17957
  auth = username + ':' + password;
17672
17958
  }
17673
17959
  if (!auth && parsed.username) {
17674
- const urlUsername = parsed.username;
17675
- const urlPassword = parsed.password;
17960
+ const urlUsername = decodeURIComponentSafe(parsed.username);
17961
+ const urlPassword = decodeURIComponentSafe(parsed.password);
17676
17962
  auth = urlUsername + ':' + urlPassword;
17677
17963
  }
17678
17964
  auth && headers.delete('authorization');
17679
- let path;
17965
+ let path$1;
17680
17966
  try {
17681
- path = buildURL(parsed.pathname + parsed.search, config.params, config.paramsSerializer).replace(/^\?/, '');
17967
+ path$1 = buildURL(parsed.pathname + parsed.search, config.params, config.paramsSerializer).replace(/^\?/, '');
17682
17968
  } catch (err) {
17683
17969
  const customErr = new Error(err.message);
17684
17970
  customErr.config = config;
@@ -17687,8 +17973,11 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17687
17973
  return reject(customErr);
17688
17974
  }
17689
17975
  headers.set('Accept-Encoding', 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false);
17690
- const options = {
17691
- path,
17976
+
17977
+ // Null-prototype to block prototype pollution gadgets on properties read
17978
+ // directly by Node's http.request (e.g. insecureHTTPParser, lookup).
17979
+ const options = Object.assign(Object.create(null), {
17980
+ path: path$1,
17692
17981
  method: method,
17693
17982
  headers: headers.toJSON(),
17694
17983
  agents: {
@@ -17699,13 +17988,24 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17699
17988
  protocol,
17700
17989
  family,
17701
17990
  beforeRedirect: dispatchBeforeRedirect,
17702
- beforeRedirects: {},
17991
+ beforeRedirects: Object.create(null),
17703
17992
  http2Options
17704
- };
17993
+ });
17705
17994
 
17706
17995
  // cacheable-lookup integration hotfix
17707
17996
  !utils$1$1.isUndefined(lookup) && (options.lookup = lookup);
17708
17997
  if (config.socketPath) {
17998
+ if (typeof config.socketPath !== 'string') {
17999
+ return reject(new AxiosError('socketPath must be a string', AxiosError.ERR_BAD_OPTION_VALUE, config));
18000
+ }
18001
+ if (config.allowedSocketPaths != null) {
18002
+ const allowed = Array.isArray(config.allowedSocketPaths) ? config.allowedSocketPaths : [config.allowedSocketPaths];
18003
+ const resolvedSocket = path.resolve(config.socketPath);
18004
+ const isAllowed = allowed.some(entry => typeof entry === 'string' && path.resolve(entry) === resolvedSocket);
18005
+ if (!isAllowed) {
18006
+ return reject(new AxiosError(`socketPath "${config.socketPath}" is not permitted by allowedSocketPaths`, AxiosError.ERR_BAD_OPTION_VALUE, config));
18007
+ }
18008
+ }
17709
18009
  options.socketPath = config.socketPath;
17710
18010
  } else {
17711
18011
  options.hostname = parsed.hostname.startsWith('[') ? parsed.hostname.slice(1, -1) : parsed.hostname;
@@ -17713,21 +18013,25 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17713
18013
  setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
17714
18014
  }
17715
18015
  let transport;
18016
+ let isNativeTransport = false;
17716
18017
  const isHttpsRequest = isHttps.test(options.protocol);
17717
18018
  options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
17718
18019
  if (isHttp2) {
17719
18020
  transport = http2Transport;
17720
18021
  } else {
17721
- if (config.transport) {
17722
- transport = config.transport;
18022
+ const configTransport = own('transport');
18023
+ if (configTransport) {
18024
+ transport = configTransport;
17723
18025
  } else if (config.maxRedirects === 0) {
17724
18026
  transport = isHttpsRequest ? https : http;
18027
+ isNativeTransport = true;
17725
18028
  } else {
17726
18029
  if (config.maxRedirects) {
17727
18030
  options.maxRedirects = config.maxRedirects;
17728
18031
  }
17729
- if (config.beforeRedirect) {
17730
- options.beforeRedirects.config = config.beforeRedirect;
18032
+ const configBeforeRedirect = own('beforeRedirect');
18033
+ if (configBeforeRedirect) {
18034
+ options.beforeRedirects.config = configBeforeRedirect;
17731
18035
  }
17732
18036
  transport = isHttpsRequest ? httpsFollow : httpFollow;
17733
18037
  }
@@ -17738,12 +18042,15 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17738
18042
  // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
17739
18043
  options.maxBodyLength = Infinity;
17740
18044
  }
17741
- if (config.insecureHTTPParser) {
17742
- options.insecureHTTPParser = config.insecureHTTPParser;
17743
- }
18045
+
18046
+ // Always set an explicit own value so a polluted
18047
+ // Object.prototype.insecureHTTPParser cannot enable the lenient parser
18048
+ // through Node's internal options copy
18049
+ options.insecureHTTPParser = Boolean(own('insecureHTTPParser'));
17744
18050
 
17745
18051
  // Create the request
17746
18052
  req = transport.request(options, function handleResponse(res) {
18053
+ clearConnectPhaseTimer();
17747
18054
  if (req.destroyed) return;
17748
18055
  const streams = [res];
17749
18056
  const responseLength = utils$1$1.toFiniteNumber(res.headers['content-length']);
@@ -17805,6 +18112,52 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17805
18112
  request: lastRequest
17806
18113
  };
17807
18114
  if (responseType === 'stream') {
18115
+ // Enforce maxContentLength on streamed responses; previously this
18116
+ // was applied only to buffered responses.
18117
+ if (config.maxContentLength > -1) {
18118
+ const limit = config.maxContentLength;
18119
+ const source = responseStream;
18120
+ function enforceMaxContentLength() {
18121
+ return _enforceMaxContentLength.apply(this, arguments);
18122
+ }
18123
+ function _enforceMaxContentLength() {
18124
+ _enforceMaxContentLength = _wrapAsyncGenerator(function* () {
18125
+ let totalResponseBytes = 0;
18126
+ var _iteratorAbruptCompletion = false;
18127
+ var _didIteratorError = false;
18128
+ var _iteratorError;
18129
+ try {
18130
+ for (var _iterator2 = _asyncIterator(source), _step; _iteratorAbruptCompletion = !(_step = yield _awaitAsyncGenerator(_iterator2.next())).done; _iteratorAbruptCompletion = false) {
18131
+ const chunk = _step.value;
18132
+ {
18133
+ totalResponseBytes += chunk.length;
18134
+ if (totalResponseBytes > limit) {
18135
+ throw new AxiosError('maxContentLength size of ' + limit + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, lastRequest);
18136
+ }
18137
+ yield chunk;
18138
+ }
18139
+ }
18140
+ } catch (err) {
18141
+ _didIteratorError = true;
18142
+ _iteratorError = err;
18143
+ } finally {
18144
+ try {
18145
+ if (_iteratorAbruptCompletion && _iterator2.return != null) {
18146
+ yield _awaitAsyncGenerator(_iterator2.return());
18147
+ }
18148
+ } finally {
18149
+ if (_didIteratorError) {
18150
+ throw _iteratorError;
18151
+ }
18152
+ }
18153
+ }
18154
+ });
18155
+ return _enforceMaxContentLength.apply(this, arguments);
18156
+ }
18157
+ responseStream = stream.Readable.from(enforceMaxContentLength(), {
18158
+ objectMode: false
18159
+ });
18160
+ }
17808
18161
  response.data = responseStream;
17809
18162
  settle(resolve, reject, response);
17810
18163
  } else {
@@ -17826,13 +18179,13 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17826
18179
  if (rejected) {
17827
18180
  return;
17828
18181
  }
17829
- const err = new AxiosError('stream has been aborted', AxiosError.ERR_BAD_RESPONSE, config, lastRequest);
18182
+ const err = new AxiosError('stream has been aborted', AxiosError.ERR_BAD_RESPONSE, config, lastRequest, response);
17830
18183
  responseStream.destroy(err);
17831
18184
  reject(err);
17832
18185
  });
17833
18186
  responseStream.on('error', function handleStreamError(err) {
17834
- if (req.destroyed) return;
17835
- reject(AxiosError.from(err, null, config, lastRequest));
18187
+ if (rejected) return;
18188
+ reject(AxiosError.from(err, null, config, lastRequest, response));
17836
18189
  });
17837
18190
  responseStream.on('end', function handleStreamEnd() {
17838
18191
  try {
@@ -17871,9 +18224,44 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17871
18224
  });
17872
18225
 
17873
18226
  // set tcp keep alive to prevent drop connection by peer
18227
+ // Track every socket bound to this outer RedirectableRequest so a single
18228
+ // 'close' listener can release ownership on all of them. follow-redirects
18229
+ // re-emits the 'socket' event for each hop's native request onto the same
18230
+ // outer request, so attaching per-request listeners inside this handler
18231
+ // would accumulate across hops and trigger MaxListenersExceededWarning at
18232
+ // >= 11 redirects. Clearing only the last-bound socket would leave stale
18233
+ // kAxiosCurrentReq refs on earlier hop sockets returned to the keep-alive
18234
+ // pool, causing an idle-pool 'error' to be attributed to a closed req.
18235
+ const boundSockets = new Set();
17874
18236
  req.on('socket', function handleRequestSocket(socket) {
17875
18237
  // default interval of sending ack packet is 1 minute
17876
18238
  socket.setKeepAlive(true, 1000 * 60);
18239
+
18240
+ // Install a single 'error' listener per socket (not per request) to avoid
18241
+ // accumulating listeners on pooled keep-alive sockets that get reassigned
18242
+ // to new requests before the previous request's 'close' fires (issue #10780).
18243
+ // The listener is bound to the socket's currently-active request via a
18244
+ // symbol, which is swapped as the socket is reassigned.
18245
+ if (!socket[kAxiosSocketListener]) {
18246
+ socket.on('error', function handleSocketError(err) {
18247
+ const current = socket[kAxiosCurrentReq];
18248
+ if (current && !current.destroyed) {
18249
+ current.destroy(err);
18250
+ }
18251
+ });
18252
+ socket[kAxiosSocketListener] = true;
18253
+ }
18254
+ socket[kAxiosCurrentReq] = req;
18255
+ boundSockets.add(socket);
18256
+ });
18257
+ req.once('close', function clearCurrentReq() {
18258
+ clearConnectPhaseTimer();
18259
+ for (const socket of boundSockets) {
18260
+ if (socket[kAxiosCurrentReq] === req) {
18261
+ socket[kAxiosCurrentReq] = null;
18262
+ }
18263
+ }
18264
+ boundSockets.clear();
17877
18265
  });
17878
18266
 
17879
18267
  // Handle request timeout
@@ -17884,21 +18272,23 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17884
18272
  abort(new AxiosError('error trying to parse `config.timeout` to int', AxiosError.ERR_BAD_OPTION_VALUE, config, req));
17885
18273
  return;
17886
18274
  }
18275
+ const handleTimeout = function handleTimeout() {
18276
+ if (isDone) return;
18277
+ abort(createTimeoutError());
18278
+ };
18279
+ if (isNativeTransport && timeout > 0) {
18280
+ // Native ClientRequest#setTimeout starts from the socket lifecycle and
18281
+ // may not fire while TCP connect is still pending. Mirror the
18282
+ // follow-redirects wall-clock timer for the maxRedirects === 0 path.
18283
+ connectPhaseTimer = setTimeout(handleTimeout, timeout);
18284
+ }
17887
18285
 
17888
18286
  // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
17889
18287
  // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
17890
18288
  // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
17891
18289
  // And then these socket which be hang up will devouring CPU little by little.
17892
18290
  // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
17893
- req.setTimeout(timeout, function handleRequestTimeout() {
17894
- if (isDone) return;
17895
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
17896
- const transitional = config.transitional || transitionalDefaults;
17897
- if (config.timeoutErrorMessage) {
17898
- timeoutErrorMessage = config.timeoutErrorMessage;
17899
- }
17900
- abort(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, req));
17901
- });
18291
+ req.setTimeout(timeout, handleTimeout);
17902
18292
  } else {
17903
18293
  // explicitly reset the socket timeout value for a possible `keep-alive` request
17904
18294
  req.setTimeout(0);
@@ -17920,7 +18310,28 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17920
18310
  abort(new CanceledError('Request stream has been aborted', config, req));
17921
18311
  }
17922
18312
  });
17923
- data.pipe(req);
18313
+
18314
+ // Enforce maxBodyLength for streamed uploads on the native http/https
18315
+ // transport (maxRedirects === 0); follow-redirects enforces it on the
18316
+ // other path.
18317
+ let uploadStream = data;
18318
+ if (config.maxBodyLength > -1 && config.maxRedirects === 0) {
18319
+ const limit = config.maxBodyLength;
18320
+ let bytesSent = 0;
18321
+ uploadStream = stream.pipeline([data, new stream.Transform({
18322
+ transform(chunk, _enc, cb) {
18323
+ bytesSent += chunk.length;
18324
+ if (bytesSent > limit) {
18325
+ return cb(new AxiosError('Request body larger than maxBodyLength limit', AxiosError.ERR_BAD_REQUEST, config, req));
18326
+ }
18327
+ cb(null, chunk);
18328
+ }
18329
+ })], utils$1$1.noop);
18330
+ uploadStream.on('error', err => {
18331
+ if (!req.destroyed) req.destroy(err);
18332
+ });
18333
+ }
18334
+ uploadStream.pipe(req);
17924
18335
  } else {
17925
18336
  data && req.write(data);
17926
18337
  req.end();
@@ -17956,8 +18367,20 @@ var cookies = platform.hasStandardBrowserEnv ?
17956
18367
  },
17957
18368
  read(name) {
17958
18369
  if (typeof document === 'undefined') return null;
17959
- const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
17960
- return match ? decodeURIComponent(match[1]) : null;
18370
+ // Match name=value by splitting on the semicolon separator instead of building a
18371
+ // RegExp from `name` interpolating an unescaped string into a RegExp would let
18372
+ // metacharacters (e.g. `.+?` in an attacker-influenced cookie name) cause ReDoS or
18373
+ // match the wrong cookie. Browsers may serialize cookie pairs as either ";" or
18374
+ // "; ", so ignore optional whitespace before each cookie name.
18375
+ const cookies = document.cookie.split(';');
18376
+ for (let i = 0; i < cookies.length; i++) {
18377
+ const cookie = cookies[i].replace(/^\s+/, '');
18378
+ const eq = cookie.indexOf('=');
18379
+ if (eq !== -1 && cookie.slice(0, eq) === name) {
18380
+ return decodeURIComponent(cookie.slice(eq + 1));
18381
+ }
18382
+ }
18383
+ return null;
17961
18384
  },
17962
18385
  remove(name) {
17963
18386
  this.write(name, '', Date.now() - 86400000, '/');
@@ -17985,7 +18408,21 @@ const headersToObject = thing => thing instanceof AxiosHeaders ? _objectSpread2(
17985
18408
  function mergeConfig(config1, config2) {
17986
18409
  // eslint-disable-next-line no-param-reassign
17987
18410
  config2 = config2 || {};
17988
- const config = {};
18411
+
18412
+ // Use a null-prototype object so that downstream reads such as `config.auth`
18413
+ // or `config.baseURL` cannot inherit polluted values from Object.prototype.
18414
+ // `hasOwnProperty` is restored as a non-enumerable own slot to preserve
18415
+ // ergonomics for user code that relies on it.
18416
+ const config = Object.create(null);
18417
+ Object.defineProperty(config, 'hasOwnProperty', {
18418
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
18419
+ // this data descriptor into an accessor descriptor on the way in.
18420
+ __proto__: null,
18421
+ value: Object.prototype.hasOwnProperty,
18422
+ enumerable: false,
18423
+ writable: true,
18424
+ configurable: true
18425
+ });
17989
18426
  function getMergedValue(target, source, prop, caseless) {
17990
18427
  if (utils$1$1.isPlainObject(target) && utils$1$1.isPlainObject(source)) {
17991
18428
  return utils$1$1.merge.call({
@@ -18024,9 +18461,9 @@ function mergeConfig(config1, config2) {
18024
18461
 
18025
18462
  // eslint-disable-next-line consistent-return
18026
18463
  function mergeDirectKeys(a, b, prop) {
18027
- if (prop in config2) {
18464
+ if (utils$1$1.hasOwnProp(config2, prop)) {
18028
18465
  return getMergedValue(a, b);
18029
- } else if (prop in config1) {
18466
+ } else if (utils$1$1.hasOwnProp(config1, prop)) {
18030
18467
  return getMergedValue(undefined, a);
18031
18468
  }
18032
18469
  }
@@ -18057,6 +18494,7 @@ function mergeConfig(config1, config2) {
18057
18494
  httpsAgent: defaultToConfig2,
18058
18495
  cancelToken: defaultToConfig2,
18059
18496
  socketPath: defaultToConfig2,
18497
+ allowedSocketPaths: defaultToConfig2,
18060
18498
  responseEncoding: defaultToConfig2,
18061
18499
  validateStatus: mergeDirectKeys,
18062
18500
  headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
@@ -18064,41 +18502,63 @@ function mergeConfig(config1, config2) {
18064
18502
  utils$1$1.forEach(Object.keys(_objectSpread2(_objectSpread2({}, config1), config2)), function computeConfigValue(prop) {
18065
18503
  if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
18066
18504
  const merge = utils$1$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
18067
- const configValue = merge(config1[prop], config2[prop], prop);
18505
+ const a = utils$1$1.hasOwnProp(config1, prop) ? config1[prop] : undefined;
18506
+ const b = utils$1$1.hasOwnProp(config2, prop) ? config2[prop] : undefined;
18507
+ const configValue = merge(a, b, prop);
18068
18508
  utils$1$1.isUndefined(configValue) && merge !== mergeDirectKeys || (config[prop] = configValue);
18069
18509
  });
18070
18510
  return config;
18071
18511
  }
18512
+ const FORM_DATA_CONTENT_HEADERS = ['content-type', 'content-length'];
18513
+ function setFormDataHeaders(headers, formHeaders, policy) {
18514
+ if (policy !== 'content-only') {
18515
+ headers.set(formHeaders);
18516
+ return;
18517
+ }
18518
+ Object.entries(formHeaders).forEach(([key, val]) => {
18519
+ if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
18520
+ headers.set(key, val);
18521
+ }
18522
+ });
18523
+ }
18524
+
18525
+ /**
18526
+ * Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
18527
+ * This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
18528
+ *
18529
+ * @param {string} str The string to encode
18530
+ *
18531
+ * @returns {string} UTF-8 bytes as a Latin-1 string
18532
+ */
18533
+ const encodeUTF8 = str => encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
18072
18534
  var resolveConfig = config => {
18073
18535
  const newConfig = mergeConfig({}, config);
18074
- let {
18075
- data,
18076
- withXSRFToken,
18077
- xsrfHeaderName,
18078
- xsrfCookieName,
18079
- headers,
18080
- auth
18081
- } = newConfig;
18536
+
18537
+ // Read only own properties to prevent prototype pollution gadgets
18538
+ // (e.g. Object.prototype.baseURL = 'https://evil.com').
18539
+ const own = key => utils$1$1.hasOwnProp(newConfig, key) ? newConfig[key] : undefined;
18540
+ const data = own('data');
18541
+ let withXSRFToken = own('withXSRFToken');
18542
+ const xsrfHeaderName = own('xsrfHeaderName');
18543
+ const xsrfCookieName = own('xsrfCookieName');
18544
+ let headers = own('headers');
18545
+ const auth = own('auth');
18546
+ const baseURL = own('baseURL');
18547
+ const allowAbsoluteUrls = own('allowAbsoluteUrls');
18548
+ const url = own('url');
18082
18549
  newConfig.headers = headers = AxiosHeaders.from(headers);
18083
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
18550
+ newConfig.url = buildURL(buildFullPath(baseURL, url, allowAbsoluteUrls), config.params, config.paramsSerializer);
18084
18551
 
18085
18552
  // HTTP basic authentication
18086
18553
  if (auth) {
18087
- headers.set('Authorization', 'Basic ' + btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : '')));
18554
+ headers.set('Authorization', 'Basic ' + btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : '')));
18088
18555
  }
18089
18556
  if (utils$1$1.isFormData(data)) {
18090
18557
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
18091
18558
  headers.setContentType(undefined); // browser handles it
18092
18559
  } else if (utils$1$1.isFunction(data.getHeaders)) {
18093
18560
  // Node.js FormData (like form-data package)
18094
- const formHeaders = data.getHeaders();
18095
- // Only set safe headers to avoid overwriting security headers
18096
- const allowedHeaders = ['content-type', 'content-length'];
18097
- Object.entries(formHeaders).forEach(([key, val]) => {
18098
- if (allowedHeaders.includes(key.toLowerCase())) {
18099
- headers.set(key, val);
18100
- }
18101
- });
18561
+ setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
18102
18562
  }
18103
18563
  }
18104
18564
 
@@ -18107,9 +18567,15 @@ var resolveConfig = config => {
18107
18567
  // Specifically not if we're in a web worker, or react-native.
18108
18568
 
18109
18569
  if (platform.hasStandardBrowserEnv) {
18110
- withXSRFToken && utils$1$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
18111
- if (withXSRFToken || withXSRFToken !== false && isURLSameOrigin(newConfig.url)) {
18112
- // Add xsrf header
18570
+ if (utils$1$1.isFunction(withXSRFToken)) {
18571
+ withXSRFToken = withXSRFToken(newConfig);
18572
+ }
18573
+
18574
+ // Strict boolean check — prevents proto-pollution gadgets (e.g. Object.prototype.withXSRFToken = 1)
18575
+ // and misconfigurations (e.g. "false") from short-circuiting the same-origin check and leaking
18576
+ // the XSRF token cross-origin.
18577
+ const shouldSendXSRF = withXSRFToken === true || withXSRFToken == null && isURLSameOrigin(newConfig.url);
18578
+ if (shouldSendXSRF) {
18113
18579
  const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
18114
18580
  if (xsrfValue) {
18115
18581
  headers.set(xsrfHeaderName, xsrfValue);
@@ -18184,7 +18650,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18184
18650
  // handled by onerror instead
18185
18651
  // With one exception: request that using file: protocol, most browsers
18186
18652
  // will return status as 0 even though it's a successful request
18187
- if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
18653
+ if (request.status === 0 && !(request.responseURL && request.responseURL.startsWith('file:'))) {
18188
18654
  return;
18189
18655
  }
18190
18656
  // readystate handler is calling before onerror or ontimeout handlers,
@@ -18199,6 +18665,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18199
18665
  return;
18200
18666
  }
18201
18667
  reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
18668
+ done();
18202
18669
 
18203
18670
  // Clean up request
18204
18671
  request = null;
@@ -18214,6 +18681,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18214
18681
  // attach the underlying event for consumers who want details
18215
18682
  err.event = event || null;
18216
18683
  reject(err);
18684
+ done();
18217
18685
  request = null;
18218
18686
  };
18219
18687
 
@@ -18225,6 +18693,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18225
18693
  timeoutErrorMessage = _config.timeoutErrorMessage;
18226
18694
  }
18227
18695
  reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, request));
18696
+ done();
18228
18697
 
18229
18698
  // Clean up request
18230
18699
  request = null;
@@ -18271,6 +18740,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18271
18740
  }
18272
18741
  reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
18273
18742
  request.abort();
18743
+ done();
18274
18744
  request = null;
18275
18745
  };
18276
18746
  _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
@@ -18279,7 +18749,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18279
18749
  }
18280
18750
  }
18281
18751
  const protocol = parseProtocol(_config.url);
18282
- if (protocol && platform.protocols.indexOf(protocol) === -1) {
18752
+ if (protocol && !platform.protocols.includes(protocol)) {
18283
18753
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
18284
18754
  return;
18285
18755
  }
@@ -18341,27 +18811,27 @@ const streamChunk = function* (chunk, chunkSize) {
18341
18811
  };
18342
18812
  const readBytes = /*#__PURE__*/function () {
18343
18813
  var _ref3 = _wrapAsyncGenerator(function* (iterable, chunkSize) {
18344
- var _iteratorAbruptCompletion = false;
18345
- var _didIteratorError = false;
18346
- var _iteratorError;
18814
+ var _iteratorAbruptCompletion2 = false;
18815
+ var _didIteratorError2 = false;
18816
+ var _iteratorError2;
18347
18817
  try {
18348
- for (var _iterator2 = _asyncIterator(readStream(iterable)), _step; _iteratorAbruptCompletion = !(_step = yield _awaitAsyncGenerator(_iterator2.next())).done; _iteratorAbruptCompletion = false) {
18349
- const chunk = _step.value;
18818
+ for (var _iterator3 = _asyncIterator(readStream(iterable)), _step2; _iteratorAbruptCompletion2 = !(_step2 = yield _awaitAsyncGenerator(_iterator3.next())).done; _iteratorAbruptCompletion2 = false) {
18819
+ const chunk = _step2.value;
18350
18820
  {
18351
18821
  yield* _asyncGeneratorDelegate(_asyncIterator(streamChunk(chunk, chunkSize)), _awaitAsyncGenerator);
18352
18822
  }
18353
18823
  }
18354
18824
  } catch (err) {
18355
- _didIteratorError = true;
18356
- _iteratorError = err;
18825
+ _didIteratorError2 = true;
18826
+ _iteratorError2 = err;
18357
18827
  } finally {
18358
18828
  try {
18359
- if (_iteratorAbruptCompletion && _iterator2.return != null) {
18360
- yield _awaitAsyncGenerator(_iterator2.return());
18829
+ if (_iteratorAbruptCompletion2 && _iterator3.return != null) {
18830
+ yield _awaitAsyncGenerator(_iterator3.return());
18361
18831
  }
18362
18832
  } finally {
18363
- if (_didIteratorError) {
18364
- throw _iteratorError;
18833
+ if (_didIteratorError2) {
18834
+ throw _iteratorError2;
18365
18835
  }
18366
18836
  }
18367
18837
  }
@@ -18441,17 +18911,6 @@ const DEFAULT_CHUNK_SIZE = 64 * 1024;
18441
18911
  const {
18442
18912
  isFunction
18443
18913
  } = utils$1$1;
18444
- const globalFetchAPI = (({
18445
- Request,
18446
- Response
18447
- }) => ({
18448
- Request,
18449
- Response
18450
- }))(utils$1$1.global);
18451
- const {
18452
- ReadableStream: ReadableStream$1,
18453
- TextEncoder: TextEncoder$1
18454
- } = utils$1$1.global;
18455
18914
  const test = (fn, ...args) => {
18456
18915
  try {
18457
18916
  return !!fn(...args);
@@ -18460,9 +18919,18 @@ const test = (fn, ...args) => {
18460
18919
  }
18461
18920
  };
18462
18921
  const factory = env => {
18922
+ var _utils$global;
18923
+ const globalObject = (_utils$global = utils$1$1.global) !== null && _utils$global !== void 0 ? _utils$global : globalThis;
18924
+ const {
18925
+ ReadableStream,
18926
+ TextEncoder
18927
+ } = globalObject;
18463
18928
  env = utils$1$1.merge.call({
18464
18929
  skipUndefined: true
18465
- }, globalFetchAPI, env);
18930
+ }, {
18931
+ Request: globalObject.Request,
18932
+ Response: globalObject.Response
18933
+ }, env);
18466
18934
  const {
18467
18935
  fetch: envFetch,
18468
18936
  Request,
@@ -18474,20 +18942,22 @@ const factory = env => {
18474
18942
  if (!isFetchSupported) {
18475
18943
  return false;
18476
18944
  }
18477
- const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
18478
- const encodeText = isFetchSupported && (typeof TextEncoder$1 === 'function' ? (encoder => str => encoder.encode(str))(new TextEncoder$1()) : async str => new Uint8Array(await new Request(str).arrayBuffer()));
18945
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
18946
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ? (encoder => str => encoder.encode(str))(new TextEncoder()) : async str => new Uint8Array(await new Request(str).arrayBuffer()));
18479
18947
  const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
18480
18948
  let duplexAccessed = false;
18481
- const body = new ReadableStream$1();
18482
- const hasContentType = new Request(platform.origin, {
18483
- body,
18949
+ const request = new Request(platform.origin, {
18950
+ body: new ReadableStream(),
18484
18951
  method: 'POST',
18485
18952
  get duplex() {
18486
18953
  duplexAccessed = true;
18487
18954
  return 'half';
18488
18955
  }
18489
- }).headers.has('Content-Type');
18490
- body.cancel();
18956
+ });
18957
+ const hasContentType = request.headers.has('Content-Type');
18958
+ if (request.body != null) {
18959
+ request.body.cancel();
18960
+ }
18491
18961
  return duplexAccessed && !hasContentType;
18492
18962
  });
18493
18963
  const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils$1$1.isReadableStream(new Response('').body));
@@ -18546,8 +19016,12 @@ const factory = env => {
18546
19016
  responseType,
18547
19017
  headers,
18548
19018
  withCredentials = 'same-origin',
18549
- fetchOptions
19019
+ fetchOptions,
19020
+ maxContentLength,
19021
+ maxBodyLength
18550
19022
  } = resolveConfig(config);
19023
+ const hasMaxContentLength = utils$1$1.isNumber(maxContentLength) && maxContentLength > -1;
19024
+ const hasMaxBodyLength = utils$1$1.isNumber(maxBodyLength) && maxBodyLength > -1;
18551
19025
  let _fetch = envFetch || fetch;
18552
19026
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
18553
19027
  let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
@@ -18557,6 +19031,26 @@ const factory = env => {
18557
19031
  });
18558
19032
  let requestContentLength;
18559
19033
  try {
19034
+ // Enforce maxContentLength for data: URLs up-front so we never materialize
19035
+ // an oversized payload. The HTTP adapter applies the same check (see http.js
19036
+ // "if (protocol === 'data:')" branch).
19037
+ if (hasMaxContentLength && typeof url === 'string' && url.startsWith('data:')) {
19038
+ const estimated = estimateDataURLDecodedBytes(url);
19039
+ if (estimated > maxContentLength) {
19040
+ throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
19041
+ }
19042
+ }
19043
+
19044
+ // Enforce maxBodyLength against the outbound request body before dispatch.
19045
+ // Mirrors http.js behavior (ERR_BAD_REQUEST / 'Request body larger than
19046
+ // maxBodyLength limit'). Skip when the body length cannot be determined
19047
+ // (e.g. a live ReadableStream supplied by the caller).
19048
+ if (hasMaxBodyLength && method !== 'get' && method !== 'head') {
19049
+ const outboundLength = await resolveBodyLength(headers, data);
19050
+ if (typeof outboundLength === 'number' && isFinite(outboundLength) && outboundLength > maxBodyLength) {
19051
+ throw new AxiosError('Request body larger than maxBodyLength limit', AxiosError.ERR_BAD_REQUEST, config, request);
19052
+ }
19053
+ }
18560
19054
  if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' && (requestContentLength = await resolveBodyLength(headers, data)) !== 0) {
18561
19055
  let _request = new Request(url, {
18562
19056
  method: 'POST',
@@ -18579,6 +19073,18 @@ const factory = env => {
18579
19073
  // Cloudflare Workers throws when credentials are defined
18580
19074
  // see https://github.com/cloudflare/workerd/issues/902
18581
19075
  const isCredentialsSupported = isRequestSupported && 'credentials' in Request.prototype;
19076
+
19077
+ // If data is FormData and Content-Type is multipart/form-data without boundary,
19078
+ // delete it so fetch can set it correctly with the boundary
19079
+ if (utils$1$1.isFormData(data)) {
19080
+ const contentType = headers.getContentType();
19081
+ if (contentType && /^multipart\/form-data/i.test(contentType) && !/boundary=/i.test(contentType)) {
19082
+ headers.delete('content-type');
19083
+ }
19084
+ }
19085
+
19086
+ // Set User-Agent header if not already set (fetch defaults to 'node' in Node.js)
19087
+ headers.set('User-Agent', 'axios/' + VERSION, false);
18582
19088
  const resolvedOptions = _objectSpread2(_objectSpread2({}, fetchOptions), {}, {
18583
19089
  signal: composedSignal,
18584
19090
  method: method.toUpperCase(),
@@ -18589,21 +19095,59 @@ const factory = env => {
18589
19095
  });
18590
19096
  request = isRequestSupported && new Request(url, resolvedOptions);
18591
19097
  let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
19098
+
19099
+ // Cheap pre-check: if the server honestly declares a content-length that
19100
+ // already exceeds the cap, reject before we start streaming.
19101
+ if (hasMaxContentLength) {
19102
+ const declaredLength = utils$1$1.toFiniteNumber(response.headers.get('content-length'));
19103
+ if (declaredLength != null && declaredLength > maxContentLength) {
19104
+ throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
19105
+ }
19106
+ }
18592
19107
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
18593
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
19108
+ if (supportsResponseStream && response.body && (onDownloadProgress || hasMaxContentLength || isStreamResponse && unsubscribe)) {
18594
19109
  const options = {};
18595
19110
  ['status', 'statusText', 'headers'].forEach(prop => {
18596
19111
  options[prop] = response[prop];
18597
19112
  });
18598
19113
  const responseContentLength = utils$1$1.toFiniteNumber(response.headers.get('content-length'));
18599
19114
  const [onProgress, flush] = onDownloadProgress && progressEventDecorator(responseContentLength, progressEventReducer(asyncDecorator(onDownloadProgress), true)) || [];
18600
- response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
19115
+ let bytesRead = 0;
19116
+ const onChunkProgress = loadedBytes => {
19117
+ if (hasMaxContentLength) {
19118
+ bytesRead = loadedBytes;
19119
+ if (bytesRead > maxContentLength) {
19120
+ throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
19121
+ }
19122
+ }
19123
+ onProgress && onProgress(loadedBytes);
19124
+ };
19125
+ response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onChunkProgress, () => {
18601
19126
  flush && flush();
18602
19127
  unsubscribe && unsubscribe();
18603
19128
  }), options);
18604
19129
  }
18605
19130
  responseType = responseType || 'text';
18606
19131
  let responseData = await resolvers[utils$1$1.findKey(resolvers, responseType) || 'text'](response, config);
19132
+
19133
+ // Fallback enforcement for environments without ReadableStream support
19134
+ // (legacy runtimes). Detect materialized size from typed output; skip
19135
+ // streams/Response passthrough since the user will read those themselves.
19136
+ if (hasMaxContentLength && !supportsResponseStream && !isStreamResponse) {
19137
+ let materializedSize;
19138
+ if (responseData != null) {
19139
+ if (typeof responseData.byteLength === 'number') {
19140
+ materializedSize = responseData.byteLength;
19141
+ } else if (typeof responseData.size === 'number') {
19142
+ materializedSize = responseData.size;
19143
+ } else if (typeof responseData === 'string') {
19144
+ materializedSize = typeof TextEncoder === 'function' ? new TextEncoder().encode(responseData).byteLength : responseData.length;
19145
+ }
19146
+ }
19147
+ if (typeof materializedSize === 'number' && materializedSize > maxContentLength) {
19148
+ throw new AxiosError('maxContentLength size of ' + maxContentLength + ' exceeded', AxiosError.ERR_BAD_RESPONSE, config, request);
19149
+ }
19150
+ }
18607
19151
  !isStreamResponse && unsubscribe && unsubscribe();
18608
19152
  return await new Promise((resolve, reject) => {
18609
19153
  settle(resolve, reject, {
@@ -18617,6 +19161,17 @@ const factory = env => {
18617
19161
  });
18618
19162
  } catch (err) {
18619
19163
  unsubscribe && unsubscribe();
19164
+
19165
+ // Safari can surface fetch aborts as a DOMException-like object whose
19166
+ // branded getters throw. Prefer our composed signal reason before reading
19167
+ // the caught error, preserving timeout vs cancellation semantics.
19168
+ if (composedSignal && composedSignal.aborted && composedSignal.reason instanceof AxiosError) {
19169
+ const canceledError = composedSignal.reason;
19170
+ canceledError.config = config;
19171
+ request && (canceledError.request = request);
19172
+ err !== canceledError && (canceledError.cause = err);
19173
+ throw canceledError;
19174
+ }
18620
19175
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
18621
19176
  throw Object.assign(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, err && err.response), {
18622
19177
  cause: err.cause || err
@@ -18671,13 +19226,17 @@ const knownAdapters = {
18671
19226
  utils$1$1.forEach(knownAdapters, (fn, value) => {
18672
19227
  if (fn) {
18673
19228
  try {
19229
+ // Null-proto descriptors so a polluted Object.prototype.get cannot turn
19230
+ // these data descriptors into accessor descriptors on the way in.
18674
19231
  Object.defineProperty(fn, 'name', {
19232
+ __proto__: null,
18675
19233
  value
18676
19234
  });
18677
19235
  } catch (e) {
18678
19236
  // eslint-disable-next-line no-empty
18679
19237
  }
18680
19238
  Object.defineProperty(fn, 'adapterName', {
19239
+ __proto__: null,
18681
19240
  value
18682
19241
  });
18683
19242
  }
@@ -18792,8 +19351,15 @@ function dispatchRequest(config) {
18792
19351
  return adapter(config).then(function onAdapterResolution(response) {
18793
19352
  throwIfCancellationRequested(config);
18794
19353
 
18795
- // Transform response data
18796
- response.data = transformData.call(config, config.transformResponse, response);
19354
+ // Expose the current response on config so that transformResponse can
19355
+ // attach it to any AxiosError it throws (e.g. on JSON parse failure).
19356
+ // We clean it up afterwards to avoid polluting the config object.
19357
+ config.response = response;
19358
+ try {
19359
+ response.data = transformData.call(config, config.transformResponse, response);
19360
+ } finally {
19361
+ delete config.response;
19362
+ }
18797
19363
  response.headers = AxiosHeaders.from(response.headers);
18798
19364
  return response;
18799
19365
  }, function onAdapterRejection(reason) {
@@ -18802,7 +19368,12 @@ function dispatchRequest(config) {
18802
19368
 
18803
19369
  // Transform response data
18804
19370
  if (reason && reason.response) {
18805
- reason.response.data = transformData.call(config, config.transformResponse, reason.response);
19371
+ config.response = reason.response;
19372
+ try {
19373
+ reason.response.data = transformData.call(config, config.transformResponse, reason.response);
19374
+ } finally {
19375
+ delete config.response;
19376
+ }
18806
19377
  reason.response.headers = AxiosHeaders.from(reason.response.headers);
18807
19378
  }
18808
19379
  }
@@ -18872,7 +19443,9 @@ function assertOptions(options, schema, allowUnknown) {
18872
19443
  let i = keys.length;
18873
19444
  while (i-- > 0) {
18874
19445
  const opt = keys[i];
18875
- const validator = schema[opt];
19446
+ // Use hasOwnProperty so a polluted Object.prototype.<opt> cannot supply
19447
+ // a non-function validator and cause a TypeError.
19448
+ const validator = Object.prototype.hasOwnProperty.call(schema, opt) ? schema[opt] : undefined;
18876
19449
  if (validator) {
18877
19450
  const value = options[opt];
18878
19451
  const result = value === undefined || validator(value, opt, options);
@@ -19003,7 +19576,7 @@ class Axios {
19003
19576
 
19004
19577
  // Flatten headers
19005
19578
  let contextHeaders = headers && utils$1$1.merge(headers.common, headers[config.method]);
19006
- headers && utils$1$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], method => {
19579
+ headers && utils$1$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'query', 'common'], method => {
19007
19580
  delete headers[method];
19008
19581
  });
19009
19582
  config.headers = AxiosHeaders.concat(contextHeaders, headers);
@@ -19084,7 +19657,7 @@ utils$1$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNo
19084
19657
  }));
19085
19658
  };
19086
19659
  });
19087
- utils$1$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
19660
+ utils$1$1.forEach(['post', 'put', 'patch', 'query'], function forEachMethodWithData(method) {
19088
19661
  function generateHTTPMethod(isForm) {
19089
19662
  return function httpMethod(url, data, config) {
19090
19663
  return this.request(mergeConfig(config || {}, {
@@ -19098,7 +19671,12 @@ utils$1$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(metho
19098
19671
  };
19099
19672
  }
19100
19673
  Axios.prototype[method] = generateHTTPMethod();
19101
- Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
19674
+
19675
+ // QUERY is a safe/idempotent read method; multipart form bodies don't fit
19676
+ // its semantics, so no queryForm shorthand is generated.
19677
+ if (method !== 'query') {
19678
+ Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
19679
+ }
19102
19680
  });
19103
19681
 
19104
19682
  /**