axios 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /*! Axios v1.18.0 Copyright (c) 2026 Matt Zabriskie and contributors */
1
+ /*! Axios v1.18.1 Copyright (c) 2026 Matt Zabriskie and contributors */
2
2
  'use strict';
3
3
 
4
4
  var FormData$1 = require('form-data');
@@ -1353,7 +1353,19 @@ function redactConfig(config, redactKeys) {
1353
1353
  class AxiosError extends Error {
1354
1354
  static from(error, code, config, request, response, customProps) {
1355
1355
  const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
1356
- axiosError.cause = error;
1356
+ // Match native `Error` `cause` semantics: non-enumerable. The wrapped
1357
+ // error often carries circular internals (sockets, requests, agents), so
1358
+ // an enumerable `cause` makes structured loggers (pino/winston) and any
1359
+ // own-property walk throw "Converting circular structure to JSON".
1360
+ // Regression from #6982; see #7205. `__proto__: null` mirrors the
1361
+ // `message` descriptor below (prototype-pollution-safe descriptor).
1362
+ Object.defineProperty(axiosError, 'cause', {
1363
+ __proto__: null,
1364
+ value: error,
1365
+ writable: true,
1366
+ enumerable: false,
1367
+ configurable: true
1368
+ });
1357
1369
  axiosError.name = error.name;
1358
1370
 
1359
1371
  // Preserve status from the original error if not already set from response
@@ -1566,7 +1578,13 @@ function toFormData(obj, formData, options) {
1566
1578
  throw new AxiosError('Blob is not supported. Use a Buffer instead.');
1567
1579
  }
1568
1580
  if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
1569
- return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
1581
+ if (useBlob && typeof _Blob === 'function') {
1582
+ return new _Blob([value]);
1583
+ }
1584
+ if (typeof Buffer !== 'undefined') {
1585
+ return Buffer.from(value);
1586
+ }
1587
+ throw new AxiosError('Blob is not supported. Use a Buffer instead.', AxiosError.ERR_NOT_SUPPORT);
1570
1588
  }
1571
1589
  return value;
1572
1590
  }
@@ -1698,9 +1716,7 @@ prototype.append = function append(name, value) {
1698
1716
  this._pairs.push([name, value]);
1699
1717
  };
1700
1718
  prototype.toString = function toString(encoder) {
1701
- const _encode = encoder ? function (value) {
1702
- return encoder.call(this, value, encode$1);
1703
- } : encode$1;
1719
+ const _encode = encoder ? value => encoder.call(this, value, encode$1) : encode$1;
1704
1720
  return this._pairs.map(function each(pair) {
1705
1721
  return _encode(pair[0]) + '=' + _encode(pair[1]);
1706
1722
  }, '').join('&');
@@ -1731,6 +1747,7 @@ function buildURL(url, params, options) {
1731
1747
  if (!params) {
1732
1748
  return url;
1733
1749
  }
1750
+ url = url || '';
1734
1751
  const _options = utils$1.isFunction(options) ? {
1735
1752
  serialize: options
1736
1753
  } : options;
@@ -2363,7 +2380,7 @@ function getEnv(key) {
2363
2380
  return process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || '';
2364
2381
  }
2365
2382
 
2366
- const VERSION = "1.18.0";
2383
+ const VERSION = "1.18.1";
2367
2384
 
2368
2385
  function parseProtocol(url) {
2369
2386
  const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
@@ -2403,13 +2420,13 @@ function fromDataURI(uri, asBlob, options) {
2403
2420
 
2404
2421
  // RFC 2397 section 3: default mediatype is text/plain;charset=US-ASCII
2405
2422
  // Bare `data:,` leaves mime undefined; Blob normalises that to "" per spec.
2406
- let mime;
2423
+ let mime = '';
2407
2424
  if (type) {
2408
2425
  mime = params ? type + params : type;
2409
2426
  } else if (params) {
2410
2427
  mime = 'text/plain' + params;
2411
2428
  }
2412
- const buffer = Buffer.from(decodeURIComponent(body), encoding);
2429
+ const buffer = encoding === 'base64' ? Buffer.from(body, 'base64') : Buffer.from(decodeURIComponent(body), encoding);
2413
2430
  if (asBlob) {
2414
2431
  if (!_Blob) {
2415
2432
  throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
@@ -3164,6 +3181,36 @@ const kAxiosInstalledTunnel = Symbol('axios.http.installedTunnel');
3164
3181
  // so unbounded growth is not a concern in practice.
3165
3182
  const tunnelingAgentCache = new Map();
3166
3183
  const tunnelingAgentCacheUser = new WeakMap();
3184
+ // Minimum minor versions where Node's HTTP Agent supports native proxyEnv
3185
+ // handling. Checking the selected agent below also covers startup modes such
3186
+ // as NODE_OPTIONS=--use-env-proxy and --no-use-env-proxy precedence.
3187
+ const NODE_NATIVE_ENV_PROXY_SUPPORT = {
3188
+ 22: 21,
3189
+ 24: 5
3190
+ };
3191
+ function isNodeNativeEnvProxySupported(nodeVersion = process.versions && process.versions.node) {
3192
+ if (!nodeVersion) {
3193
+ return false;
3194
+ }
3195
+ const [major, minor] = nodeVersion.split('.').map(part => Number(part));
3196
+ if (!Number.isInteger(major) || !Number.isInteger(minor)) {
3197
+ return false;
3198
+ }
3199
+ if (major > 24) {
3200
+ return true;
3201
+ }
3202
+ return NODE_NATIVE_ENV_PROXY_SUPPORT[major] != null && minor >= NODE_NATIVE_ENV_PROXY_SUPPORT[major];
3203
+ }
3204
+ function isNodeEnvProxyEnabled(agent, nodeVersion = process.versions && process.versions.node) {
3205
+ if (!isNodeNativeEnvProxySupported(nodeVersion)) {
3206
+ return false;
3207
+ }
3208
+ const agentOptions = agent && agent.options;
3209
+ return Boolean(agentOptions && utils$1.hasOwnProp(agentOptions, 'proxyEnv') && agentOptions.proxyEnv != null);
3210
+ }
3211
+ function getProxyEnvAgent(options, configHttpAgent, configHttpsAgent) {
3212
+ return isHttps.test(options.protocol) ? configHttpsAgent || https.globalAgent : configHttpAgent || http.globalAgent;
3213
+ }
3167
3214
  function getTunnelingAgent(agentOptions, userHttpsAgent) {
3168
3215
  const key = agentOptions.protocol + '//' + agentOptions.hostname + ':' + (agentOptions.port || '') + '#' + (agentOptions.auth || '');
3169
3216
  const cache = userHttpsAgent ? tunnelingAgentCacheUser.get(userHttpsAgent) || tunnelingAgentCacheUser.set(userHttpsAgent, new Map()).get(userHttpsAgent) : tunnelingAgentCache;
@@ -3271,9 +3318,10 @@ function isSameOriginRedirect(redirectOptions, requestDetails) {
3271
3318
  *
3272
3319
  * @returns {http.ClientRequestArgs}
3273
3320
  */
3274
- function setProxy(options, configProxy, location, isRedirect, configHttpsAgent) {
3321
+ function setProxy(options, configProxy, location, isRedirect, configHttpsAgent, configHttpAgent) {
3275
3322
  let proxy = configProxy;
3276
- if (!proxy && proxy !== false) {
3323
+ const proxyEnvAgent = getProxyEnvAgent(options, configHttpAgent, configHttpsAgent);
3324
+ if (!proxy && proxy !== false && !isNodeEnvProxyEnabled(proxyEnvAgent)) {
3277
3325
  const proxyUrl = getProxyForUrl(location);
3278
3326
  if (proxyUrl) {
3279
3327
  if (!shouldBypassProxy(location)) {
@@ -3408,7 +3456,7 @@ function setProxy(options, configProxy, location, isRedirect, configHttpsAgent)
3408
3456
  options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
3409
3457
  // Configure proxy for redirected request, passing the original config proxy to apply
3410
3458
  // the exact same logic as if the redirected request was performed by axios directly.
3411
- setProxy(redirectOptions, configProxy, redirectOptions.href, true, configHttpsAgent);
3459
+ setProxy(redirectOptions, configProxy, redirectOptions.href, true, configHttpsAgent, configHttpAgent);
3412
3460
  };
3413
3461
  }
3414
3462
  const isHttpAdapterSupported = typeof process !== 'undefined' && utils$1.kindOf(process) === 'process';
@@ -3504,10 +3552,12 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3504
3552
  let httpVersion = own('httpVersion');
3505
3553
  if (httpVersion === undefined) httpVersion = 1;
3506
3554
  let http2Options = own('http2Options');
3507
- const responseType = own('responseType');
3508
- const responseEncoding = own('responseEncoding');
3509
3555
  const httpAgent = own('httpAgent');
3510
3556
  const httpsAgent = own('httpsAgent');
3557
+ const configProxy = own('proxy');
3558
+ const responseType = own('responseType');
3559
+ const responseEncoding = own('responseEncoding');
3560
+ const socketPath = own('socketPath');
3511
3561
  const method = own('method').toUpperCase();
3512
3562
  const maxRedirects = own('maxRedirects');
3513
3563
  const maxBodyLength = own('maxBodyLength');
@@ -3601,7 +3651,12 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3601
3651
 
3602
3652
  // Parse url
3603
3653
  const fullPath = buildFullPath(own('baseURL'), own('url'), own('allowAbsoluteUrls'), config);
3604
- const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
3654
+ // Unix-socket requests (own socketPath) commonly pass a path-only url
3655
+ // like '/foo'; supply a synthetic base so new URL() can still parse it.
3656
+ // Use the own-property value (not config.socketPath) so a polluted
3657
+ // prototype cannot influence URL base selection.
3658
+ const urlBase = socketPath ? 'http://localhost' : platform.hasBrowserEnv ? platform.origin : undefined;
3659
+ const parsed = new URL(fullPath, urlBase);
3605
3660
  const protocol = parsed.protocol || supportedProtocols[0];
3606
3661
  if (protocol === 'data:') {
3607
3662
  // Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
@@ -3738,11 +3793,10 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3738
3793
  try {
3739
3794
  path$1 = buildURL(parsed.pathname + parsed.search, own('params'), own('paramsSerializer')).replace(/^\?/, '');
3740
3795
  } catch (err) {
3741
- const customErr = new Error(err.message);
3742
- customErr.config = config;
3743
- customErr.url = own('url');
3744
- customErr.exists = true;
3745
- return reject(customErr);
3796
+ return reject(AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config, null, null, {
3797
+ url: own('url'),
3798
+ exists: true
3799
+ }));
3746
3800
  }
3747
3801
  headers.set('Accept-Encoding', utils$1.hasOwnProp(transitional, 'advertiseZstdAcceptEncoding') && transitional.advertiseZstdAcceptEncoding === true ? ACCEPT_ENCODING_WITH_ZSTD : ACCEPT_ENCODING, false);
3748
3802
 
@@ -3766,7 +3820,6 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3766
3820
 
3767
3821
  // cacheable-lookup integration hotfix
3768
3822
  !utils$1.isUndefined(lookup) && (options.lookup = lookup);
3769
- const socketPath = own('socketPath');
3770
3823
  if (socketPath) {
3771
3824
  if (typeof socketPath !== 'string') {
3772
3825
  return reject(new AxiosError('socketPath must be a string', AxiosError.ERR_BAD_OPTION_VALUE, config));
@@ -3784,7 +3837,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3784
3837
  } else {
3785
3838
  options.hostname = parsed.hostname.startsWith('[') ? parsed.hostname.slice(1, -1) : parsed.hostname;
3786
3839
  options.port = parsed.port;
3787
- setProxy(options, own('proxy'), protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path, false, httpsAgent);
3840
+ setProxy(options, configProxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path, false, httpsAgent, httpAgent);
3788
3841
  }
3789
3842
  let transport;
3790
3843
  let isNativeTransport = false;
@@ -3859,10 +3912,13 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
3859
3912
  transport = isHttpsRequest ? httpsFollow : httpFollow;
3860
3913
  }
3861
3914
  }
3915
+
3916
+ // Set an explicit maxBodyLength option for transports that inspect it.
3917
+ // When maxBodyLength is -1 (default/unlimited), use Infinity so
3918
+ // follow-redirects does not fall back to its own 10MB default.
3862
3919
  if (maxBodyLength > -1) {
3863
3920
  options.maxBodyLength = maxBodyLength;
3864
3921
  } else {
3865
- // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
3866
3922
  options.maxBodyLength = Infinity;
3867
3923
  }
3868
3924
 
@@ -4038,7 +4094,11 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
4038
4094
  const boundSockets = new Set();
4039
4095
  req.on('socket', function handleRequestSocket(socket) {
4040
4096
  // default interval of sending ack packet is 1 minute
4041
- socket.setKeepAlive(true, 1000 * 60);
4097
+ // proxy agents (e.g. agent-base) may return a generic Duplex stream
4098
+ // that doesn't have setKeepAlive, so guard before calling
4099
+ if (typeof socket.setKeepAlive === 'function') {
4100
+ socket.setKeepAlive(true, 1000 * 60);
4101
+ }
4042
4102
 
4043
4103
  // Install a single 'error' listener per socket (not per request) to avoid
4044
4104
  // accumulating listeners on pooled keep-alive sockets that get reassigned
@@ -4183,7 +4243,11 @@ var cookies = platform.hasStandardBrowserEnv ?
4183
4243
  const cookie = cookies[i].replace(/^\s+/, '');
4184
4244
  const eq = cookie.indexOf('=');
4185
4245
  if (eq !== -1 && cookie.slice(0, eq) === name) {
4186
- return decodeURIComponent(cookie.slice(eq + 1));
4246
+ try {
4247
+ return decodeURIComponent(cookie.slice(eq + 1));
4248
+ } catch (e) {
4249
+ return cookie.slice(eq + 1);
4250
+ }
4187
4251
  }
4188
4252
  }
4189
4253
  return null;
@@ -4216,6 +4280,7 @@ const headersToObject = thing => thing instanceof AxiosHeaders ? {
4216
4280
  */
4217
4281
  function mergeConfig(config1, config2) {
4218
4282
  // eslint-disable-next-line no-param-reassign
4283
+ config1 = config1 || {};
4219
4284
  config2 = config2 || {};
4220
4285
 
4221
4286
  // Use a null-prototype object so that downstream reads such as `config.auth`
@@ -4352,7 +4417,7 @@ function setFormDataHeaders(headers, formHeaders, policy) {
4352
4417
  headers.set(formHeaders);
4353
4418
  return;
4354
4419
  }
4355
- Object.entries(formHeaders).forEach(([key, val]) => {
4420
+ Object.entries(formHeaders || {}).forEach(([key, val]) => {
4356
4421
  if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
4357
4422
  headers.set(key, val);
4358
4423
  }
@@ -4390,7 +4455,11 @@ function resolveConfig(config) {
4390
4455
  if (auth) {
4391
4456
  const username = utils$1.getSafeProp(auth, 'username') || '';
4392
4457
  const password = utils$1.getSafeProp(auth, 'password') || '';
4393
- headers.set('Authorization', 'Basic ' + btoa(username + ':' + (password ? encodeUTF8$1(password) : '')));
4458
+ try {
4459
+ headers.set('Authorization', 'Basic ' + btoa(username + ':' + (password ? encodeUTF8$1(password) : '')));
4460
+ } catch (e) {
4461
+ throw AxiosError.from(e, AxiosError.ERR_BAD_OPTION_VALUE, config);
4462
+ }
4394
4463
  }
4395
4464
  if (utils$1.isFormData(data)) {
4396
4465
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv || utils$1.isReactNative(data)) {
@@ -4591,6 +4660,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
4591
4660
  const protocol = parseProtocol(_config.url);
4592
4661
  if (protocol && !platform.protocols.includes(protocol)) {
4593
4662
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
4663
+ done();
4594
4664
  return;
4595
4665
  }
4596
4666
 
@@ -4629,7 +4699,9 @@ const composeSignals = (signals, timeout) => {
4629
4699
  });
4630
4700
  signals = null;
4631
4701
  };
4632
- signals.forEach(signal => signal.addEventListener('abort', onabort));
4702
+ signals.forEach(signal => signal.addEventListener('abort', onabort, {
4703
+ once: true
4704
+ }));
4633
4705
  const {
4634
4706
  signal
4635
4707
  } = controller;
@@ -5079,7 +5151,17 @@ const factory = env => {
5079
5151
  const canceledError = composedSignal.reason;
5080
5152
  canceledError.config = config;
5081
5153
  request && (canceledError.request = request);
5082
- err !== canceledError && (canceledError.cause = err);
5154
+ if (err !== canceledError) {
5155
+ // Non-enumerable to match native Error `cause` semantics so loggers
5156
+ // don't recurse into circular fetch internals (see #7205).
5157
+ Object.defineProperty(canceledError, 'cause', {
5158
+ __proto__: null,
5159
+ value: err,
5160
+ writable: true,
5161
+ enumerable: false,
5162
+ configurable: true
5163
+ });
5164
+ }
5083
5165
  throw canceledError;
5084
5166
  }
5085
5167
 
@@ -5100,9 +5182,17 @@ const factory = env => {
5100
5182
  throw err;
5101
5183
  }
5102
5184
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
5103
- throw Object.assign(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, err && err.response), {
5104
- cause: err.cause || err
5185
+ const networkError = new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, err && err.response);
5186
+ // Non-enumerable to match native Error `cause` semantics so loggers
5187
+ // don't recurse into circular fetch internals (see #7205).
5188
+ Object.defineProperty(networkError, 'cause', {
5189
+ __proto__: null,
5190
+ value: err.cause || err,
5191
+ writable: true,
5192
+ enumerable: false,
5193
+ configurable: true
5105
5194
  });
5195
+ throw networkError;
5106
5196
  }
5107
5197
  throw AxiosError.from(err, err && err.code, config, request, err && err.response);
5108
5198
  }
@@ -5221,7 +5311,7 @@ function getAdapter(adapters, config) {
5221
5311
  if (!adapter) {
5222
5312
  const reasons = Object.entries(rejectedReasons).map(([id, state]) => `adapter ${id} ` + (state === false ? 'is not supported by the environment' : 'is not available in the build'));
5223
5313
  let s = length ? reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0]) : 'as no adapter specified';
5224
- throw new AxiosError(`There is no suitable adapter to dispatch the request ` + s, 'ERR_NOT_SUPPORT');
5314
+ throw new AxiosError(`There is no suitable adapter to dispatch the request ` + s, AxiosError.ERR_NOT_SUPPORT);
5225
5315
  }
5226
5316
  return adapter;
5227
5317
  }
@@ -5364,7 +5454,7 @@ validators$1.spelling = function spelling(correctSpelling) {
5364
5454
  */
5365
5455
 
5366
5456
  function assertOptions(options, schema, allowUnknown) {
5367
- if (typeof options !== 'object') {
5457
+ if (typeof options !== 'object' || options === null) {
5368
5458
  throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
5369
5459
  }
5370
5460
  const keys = Object.keys(options);
package/index.d.cts CHANGED
@@ -50,6 +50,7 @@ declare class AxiosHeaders {
50
50
  rewrite?: boolean | AxiosHeaderMatcher
51
51
  ): AxiosHeaders;
52
52
  set(headers?: axios.RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
53
+ set(headers?: Iterable<[string, axios.AxiosHeaderValue]>, rewrite?: boolean): AxiosHeaders;
53
54
 
54
55
  get(headerName: string, parser: RegExp): RegExpExecArray | null;
55
56
  get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
@@ -119,6 +120,8 @@ declare class AxiosHeaders {
119
120
 
120
121
  getSetCookie(): string[];
121
122
 
123
+ toString(): string;
124
+
122
125
  [Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
123
126
  }
124
127
 
@@ -165,7 +168,9 @@ declare class AxiosError<T = unknown, D = any> extends Error {
165
168
  }
166
169
 
167
170
  declare class CanceledError<T> extends AxiosError<T> {
171
+ constructor(message?: string, config?: axios.InternalAxiosRequestConfig, request?: any);
168
172
  readonly name: 'CanceledError';
173
+ __CANCEL__?: boolean;
169
174
  }
170
175
 
171
176
  declare class Axios {
@@ -296,6 +301,12 @@ declare enum HttpStatusCode {
296
301
  LoopDetected = 508,
297
302
  NotExtended = 510,
298
303
  NetworkAuthenticationRequired = 511,
304
+ WebServerIsDown = 521,
305
+ ConnectionTimedOut = 522,
306
+ OriginIsUnreachable = 523,
307
+ TimeoutOccurred = 524,
308
+ SslHandshakeFailed = 525,
309
+ InvalidSslCertificate = 526,
299
310
  }
300
311
 
301
312
  type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
@@ -428,6 +439,8 @@ declare namespace axios {
428
439
  dots?: boolean;
429
440
  metaTokens?: boolean;
430
441
  indexes?: boolean | null;
442
+ maxDepth?: number;
443
+ Blob?: { new (...args: any[]): any };
431
444
  }
432
445
 
433
446
  // tslint:disable-next-line
@@ -625,6 +638,9 @@ declare namespace axios {
625
638
  promise: Promise<Cancel>;
626
639
  reason?: Cancel;
627
640
  throwIfRequested(): void;
641
+ subscribe(listener: (cancel: Cancel | any) => void): void;
642
+ unsubscribe(listener: (cancel: Cancel | any) => void): void;
643
+ toAbortSignal(): AbortSignal;
628
644
  }
629
645
 
630
646
  interface CancelTokenSource {
@@ -691,7 +707,7 @@ declare namespace axios {
691
707
  }
692
708
 
693
709
  interface AxiosStatic extends AxiosInstance {
694
- Cancel: CancelStatic;
710
+ Cancel: typeof CanceledError;
695
711
  CancelToken: CancelTokenStatic;
696
712
  Axios: typeof Axios;
697
713
  AxiosError: typeof AxiosError;
package/index.d.ts CHANGED
@@ -31,6 +31,7 @@ export class AxiosHeaders {
31
31
  rewrite?: boolean | AxiosHeaderMatcher
32
32
  ): AxiosHeaders;
33
33
  set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
34
+ set(headers?: Iterable<[string, AxiosHeaderValue]>, rewrite?: boolean): AxiosHeaders;
34
35
 
35
36
  get(headerName: string, parser: RegExp): RegExpExecArray | null;
36
37
  get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
@@ -91,6 +92,8 @@ export class AxiosHeaders {
91
92
 
92
93
  getSetCookie(): string[];
93
94
 
95
+ toString(): string;
96
+
94
97
  [Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
95
98
  }
96
99
 
@@ -233,6 +236,12 @@ export enum HttpStatusCode {
233
236
  LoopDetected = 508,
234
237
  NotExtended = 510,
235
238
  NetworkAuthenticationRequired = 511,
239
+ WebServerIsDown = 521,
240
+ ConnectionTimedOut = 522,
241
+ OriginIsUnreachable = 523,
242
+ TimeoutOccurred = 524,
243
+ SslHandshakeFailed = 525,
244
+ InvalidSslCertificate = 526,
236
245
  }
237
246
 
238
247
  type UppercaseMethod =
@@ -315,6 +324,8 @@ export interface SerializerOptions {
315
324
  dots?: boolean;
316
325
  metaTokens?: boolean;
317
326
  indexes?: boolean | null;
327
+ maxDepth?: number;
328
+ Blob?: { new (...args: any[]): any };
318
329
  }
319
330
 
320
331
  // tslint:disable-next-line
@@ -538,7 +549,9 @@ export class AxiosError<T = unknown, D = any> extends Error {
538
549
  }
539
550
 
540
551
  export class CanceledError<T> extends AxiosError<T> {
552
+ constructor(message?: string, config?: InternalAxiosRequestConfig, request?: any);
541
553
  readonly name: 'CanceledError';
554
+ __CANCEL__?: boolean;
542
555
  }
543
556
 
544
557
  export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
@@ -564,6 +577,9 @@ export interface CancelToken {
564
577
  promise: Promise<Cancel>;
565
578
  reason?: Cancel;
566
579
  throwIfRequested(): void;
580
+ subscribe(listener: (cancel: Cancel | any) => void): void;
581
+ unsubscribe(listener: (cancel: Cancel | any) => void): void;
582
+ toAbortSignal(): AbortSignal;
567
583
  }
568
584
 
569
585
  export interface CancelTokenSource {
@@ -716,7 +732,7 @@ export function mergeConfig<D = any>(
716
732
  export function create(config?: CreateAxiosDefaults): AxiosInstance;
717
733
 
718
734
  export interface AxiosStatic extends AxiosInstance {
719
- Cancel: CancelStatic;
735
+ Cancel: typeof CanceledError;
720
736
  CancelToken: CancelTokenStatic;
721
737
  Axios: typeof Axios;
722
738
  AxiosError: typeof AxiosError;
@@ -107,7 +107,7 @@ function getAdapter(adapters, config) {
107
107
 
108
108
  throw new AxiosError(
109
109
  `There is no suitable adapter to dispatch the request ` + s,
110
- 'ERR_NOT_SUPPORT'
110
+ AxiosError.ERR_NOT_SUPPORT
111
111
  );
112
112
  }
113
113
 
@@ -557,7 +557,17 @@ const factory = (env) => {
557
557
  const canceledError = composedSignal.reason;
558
558
  canceledError.config = config;
559
559
  request && (canceledError.request = request);
560
- err !== canceledError && (canceledError.cause = err);
560
+ if (err !== canceledError) {
561
+ // Non-enumerable to match native Error `cause` semantics so loggers
562
+ // don't recurse into circular fetch internals (see #7205).
563
+ Object.defineProperty(canceledError, 'cause', {
564
+ __proto__: null,
565
+ value: err,
566
+ writable: true,
567
+ enumerable: false,
568
+ configurable: true,
569
+ });
570
+ }
561
571
  throw canceledError;
562
572
  }
563
573
 
@@ -579,18 +589,23 @@ const factory = (env) => {
579
589
  }
580
590
 
581
591
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
582
- throw Object.assign(
583
- new AxiosError(
584
- 'Network Error',
585
- AxiosError.ERR_NETWORK,
586
- config,
587
- request,
588
- err && err.response
589
- ),
590
- {
591
- cause: err.cause || err,
592
- }
592
+ const networkError = new AxiosError(
593
+ 'Network Error',
594
+ AxiosError.ERR_NETWORK,
595
+ config,
596
+ request,
597
+ err && err.response
593
598
  );
599
+ // Non-enumerable to match native Error `cause` semantics so loggers
600
+ // don't recurse into circular fetch internals (see #7205).
601
+ Object.defineProperty(networkError, 'cause', {
602
+ __proto__: null,
603
+ value: err.cause || err,
604
+ writable: true,
605
+ enumerable: false,
606
+ configurable: true,
607
+ });
608
+ throw networkError;
594
609
  }
595
610
 
596
611
  throw AxiosError.from(err, err && err.code, config, request, err && err.response);