axios 1.18.0 → 1.19.0

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +192 -23
  3. package/dist/axios.js +410 -101
  4. package/dist/axios.min.js +3 -3
  5. package/dist/axios.min.js.map +1 -1
  6. package/dist/browser/axios.cjs +484 -119
  7. package/dist/esm/axios.js +484 -119
  8. package/dist/esm/axios.min.js +2 -2
  9. package/dist/esm/axios.min.js.map +1 -1
  10. package/dist/node/axios.cjs +589 -139
  11. package/index.d.cts +114 -74
  12. package/index.d.ts +112 -68
  13. package/lib/adapters/adapters.js +1 -1
  14. package/lib/adapters/fetch.js +27 -12
  15. package/lib/adapters/http.js +95 -34
  16. package/lib/adapters/xhr.js +1 -0
  17. package/lib/core/Axios.js +24 -6
  18. package/lib/core/AxiosError.js +46 -3
  19. package/lib/core/AxiosHeaders.js +124 -1
  20. package/lib/core/buildFullPath.js +45 -7
  21. package/lib/core/mergeConfig.js +19 -3
  22. package/lib/core/setFormDataHeaders.js +27 -0
  23. package/lib/env/data.js +1 -1
  24. package/lib/helpers/AxiosURLSearchParams.js +1 -3
  25. package/lib/helpers/HttpStatusCode.js +1 -0
  26. package/lib/helpers/buildURL.js +1 -0
  27. package/lib/helpers/combineURLs.js +11 -3
  28. package/lib/helpers/composeSignals.js +12 -1
  29. package/lib/helpers/cookies.js +5 -1
  30. package/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
  31. package/lib/helpers/formDataToJSON.js +11 -5
  32. package/lib/helpers/fromDataURI.js +4 -2
  33. package/lib/helpers/parseHeaders.js +5 -3
  34. package/lib/helpers/progressEventReducer.js +3 -3
  35. package/lib/helpers/resolveConfig.js +10 -19
  36. package/lib/helpers/shouldBypassProxy.js +120 -1
  37. package/lib/helpers/toFormData.js +8 -1
  38. package/lib/helpers/validator.js +1 -1
  39. package/lib/platform/node/classes/Buffer.js +11 -0
  40. package/lib/utils.js +17 -5
  41. package/package.json +22 -20
package/index.d.ts CHANGED
@@ -3,6 +3,8 @@ type StringLiteralsOrString<Literals extends string> = Literals | (string & {});
3
3
 
4
4
  export type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
5
5
 
6
+ export type AxiosHeaderParameters = Record<string, string>;
7
+
6
8
  export interface RawAxiosHeaders {
7
9
  [key: string]: AxiosHeaderValue;
8
10
  }
@@ -31,7 +33,9 @@ export class AxiosHeaders {
31
33
  rewrite?: boolean | AxiosHeaderMatcher
32
34
  ): AxiosHeaders;
33
35
  set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
36
+ set(headers?: Iterable<[string, AxiosHeaderValue]>, rewrite?: boolean): AxiosHeaders;
34
37
 
38
+ get(headerName: string, parser: typeof AxiosHeaders.parseParameters): AxiosHeaderParameters;
35
39
  get(headerName: string, parser: RegExp): RegExpExecArray | null;
36
40
  get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
37
41
 
@@ -53,6 +57,8 @@ export class AxiosHeaders {
53
57
 
54
58
  static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
55
59
 
60
+ static parseParameters(value: AxiosHeaderValue): AxiosHeaderParameters;
61
+
56
62
  static accessor(header: string | string[]): AxiosHeaders;
57
63
 
58
64
  static concat(
@@ -91,6 +97,8 @@ export class AxiosHeaders {
91
97
 
92
98
  getSetCookie(): string[];
93
99
 
100
+ toString(): string;
101
+
94
102
  [Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
95
103
  }
96
104
 
@@ -233,6 +241,13 @@ export enum HttpStatusCode {
233
241
  LoopDetected = 508,
234
242
  NotExtended = 510,
235
243
  NetworkAuthenticationRequired = 511,
244
+ WebServerReturnsAnUnknownError = 520,
245
+ WebServerIsDown = 521,
246
+ ConnectionTimedOut = 522,
247
+ OriginIsUnreachable = 523,
248
+ TimeoutOccurred = 524,
249
+ SslHandshakeFailed = 525,
250
+ InvalidSslCertificate = 526,
236
251
  }
237
252
 
238
253
  type UppercaseMethod =
@@ -315,6 +330,8 @@ export interface SerializerOptions {
315
330
  dots?: boolean;
316
331
  metaTokens?: boolean;
317
332
  indexes?: boolean | null;
333
+ maxDepth?: number;
334
+ Blob?: { new (...args: any[]): any };
318
335
  }
319
336
 
320
337
  // tslint:disable-next-line
@@ -324,13 +341,13 @@ export interface ParamEncoder {
324
341
  (value: any, defaultEncoder: (value: any) => any): any;
325
342
  }
326
343
 
327
- export interface CustomParamsSerializer {
328
- (params: Record<string, any>, options?: ParamsSerializerOptions): string;
344
+ export interface CustomParamsSerializer<P = Record<string, any>> {
345
+ (params: P, options?: ParamsSerializerOptions<P>): string;
329
346
  }
330
347
 
331
- export interface ParamsSerializerOptions extends SerializerOptions {
348
+ export interface ParamsSerializerOptions<P = Record<string, any>> extends SerializerOptions {
332
349
  encode?: ParamEncoder;
333
- serialize?: CustomParamsSerializer;
350
+ serialize?: CustomParamsSerializer<P>;
334
351
  }
335
352
 
336
353
  type MaxUploadRate = number;
@@ -367,7 +384,7 @@ export interface LookupAddressEntry {
367
384
 
368
385
  export type LookupAddress = string | LookupAddressEntry;
369
386
 
370
- export interface AxiosRequestConfig<D = any> {
387
+ export interface AxiosRequestConfig<D = any, P = any> {
371
388
  url?: string;
372
389
  method?: StringLiteralsOrString<Method>;
373
390
  baseURL?: string;
@@ -375,8 +392,10 @@ export interface AxiosRequestConfig<D = any> {
375
392
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
376
393
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
377
394
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
378
- params?: any;
379
- paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
395
+ params?: P;
396
+ paramsSerializer?:
397
+ | ParamsSerializerOptions<unknown extends P ? Record<string, any> : P>
398
+ | CustomParamsSerializer<unknown extends P ? Record<string, any> : P>;
380
399
  data?: D;
381
400
  timeout?: Milliseconds;
382
401
  timeoutErrorMessage?: string;
@@ -444,7 +463,7 @@ export interface AxiosRequestConfig<D = any> {
444
463
  ) => Promise<
445
464
  [address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress
446
465
  >);
447
- withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
466
+ withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig<D, P>) => boolean | undefined);
448
467
  parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
449
468
  fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
450
469
  httpVersion?: 1 | 2;
@@ -457,9 +476,9 @@ export interface AxiosRequestConfig<D = any> {
457
476
  }
458
477
 
459
478
  // Alias
460
- export type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
479
+ export type RawAxiosRequestConfig<D = any, P = any> = AxiosRequestConfig<D, P>;
461
480
 
462
- export interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
481
+ export interface InternalAxiosRequestConfig<D = any, P = any> extends AxiosRequestConfig<D, P> {
463
482
  headers: AxiosRequestHeaders;
464
483
  }
465
484
 
@@ -478,49 +497,52 @@ export interface HeadersDefaults {
478
497
  query?: RawAxiosRequestHeaders;
479
498
  }
480
499
 
481
- export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
500
+ export interface AxiosDefaults<D = any, P = any> extends Omit<AxiosRequestConfig<D, P>, 'headers'> {
482
501
  headers: HeadersDefaults;
483
502
  }
484
503
 
485
- export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
504
+ export interface CreateAxiosDefaults<D = any, P = any> extends Omit<
505
+ AxiosRequestConfig<D, P>,
506
+ 'headers'
507
+ > {
486
508
  headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
487
509
  }
488
510
 
489
- export interface AxiosResponse<T = any, D = any, H = {}> {
511
+ export interface AxiosResponse<T = any, D = any, H = {}, P = any> {
490
512
  data: T;
491
513
  status: number;
492
514
  statusText: string;
493
515
  headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
494
- config: InternalAxiosRequestConfig<D>;
516
+ config: InternalAxiosRequestConfig<D, P>;
495
517
  request?: any;
496
518
  }
497
519
 
498
- export class AxiosError<T = unknown, D = any> extends Error {
520
+ export class AxiosError<T = unknown, D = any, P = any> extends Error {
499
521
  constructor(
500
522
  message?: string,
501
523
  code?: string,
502
- config?: InternalAxiosRequestConfig<D>,
524
+ config?: InternalAxiosRequestConfig<D, P>,
503
525
  request?: any,
504
- response?: AxiosResponse<T, D>
526
+ response?: AxiosResponse<T, D, {}, P>
505
527
  );
506
528
 
507
- config?: InternalAxiosRequestConfig<D>;
529
+ config?: InternalAxiosRequestConfig<D, P>;
508
530
  code?: string;
509
531
  request?: any;
510
- response?: AxiosResponse<T, D>;
532
+ response?: AxiosResponse<T, D, {}, P>;
511
533
  isAxiosError: boolean;
512
534
  status?: number;
513
535
  toJSON: () => object;
514
536
  cause?: Error;
515
537
  event?: BrowserProgressEvent;
516
- static from<T = unknown, D = any>(
538
+ static from<T = unknown, D = any, P = any>(
517
539
  error: Error | unknown,
518
540
  code?: string,
519
- config?: InternalAxiosRequestConfig<D>,
541
+ config?: InternalAxiosRequestConfig<D, P>,
520
542
  request?: any,
521
- response?: AxiosResponse<T, D>,
543
+ response?: AxiosResponse<T, D, {}, P>,
522
544
  customProps?: object
523
- ): AxiosError<T, D>;
545
+ ): AxiosError<T, D, P>;
524
546
  static readonly ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
525
547
  static readonly ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
526
548
  static readonly ERR_BAD_OPTION = 'ERR_BAD_OPTION';
@@ -537,11 +559,21 @@ export class AxiosError<T = unknown, D = any> extends Error {
537
559
  static readonly ETIMEDOUT = 'ETIMEDOUT';
538
560
  }
539
561
 
540
- export class CanceledError<T> extends AxiosError<T> {
562
+ export class CanceledError<T, D = any, P = any> extends AxiosError<T, D, P> {
563
+ constructor(message?: string, config?: InternalAxiosRequestConfig<D, P>, request?: any);
541
564
  readonly name: 'CanceledError';
565
+ __CANCEL__?: boolean;
542
566
  }
543
567
 
544
- export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
568
+ declare const axiosResponseDefault: unique symbol;
569
+
570
+ type AxiosResponseDefault = typeof axiosResponseDefault;
571
+
572
+ type AxiosResponseResult<T, R, D, P> = R extends AxiosResponseDefault
573
+ ? AxiosResponse<T, D, {}, P>
574
+ : R;
575
+
576
+ export type AxiosPromise<T = any, D = any, P = any> = Promise<AxiosResponse<T, D, {}, P>>;
545
577
 
546
578
  export interface CancelStatic {
547
579
  new (message?: string): Cancel;
@@ -564,6 +596,9 @@ export interface CancelToken {
564
596
  promise: Promise<Cancel>;
565
597
  reason?: Cancel;
566
598
  throwIfRequested(): void;
599
+ subscribe(listener: (cancel: Cancel | any) => void): void;
600
+ unsubscribe(listener: (cancel: Cancel | any) => void): void;
601
+ toAbortSignal(): AbortSignal;
567
602
  }
568
603
 
569
604
  export interface CancelTokenSource {
@@ -612,63 +647,70 @@ export class Axios {
612
647
  response: AxiosInterceptorManager<AxiosResponse>;
613
648
  };
614
649
  getUri(config?: AxiosRequestConfig): string;
615
- request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
616
- get<T = any, R = AxiosResponse<T>, D = any>(
650
+ request<T = any, R = AxiosResponseDefault, D = any, P = any>(
651
+ config: AxiosRequestConfig<D, P>
652
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
653
+ get<T = any, R = AxiosResponseDefault, D = any, P = any>(
617
654
  url: string,
618
- config?: AxiosRequestConfig<D>
619
- ): Promise<R>;
620
- delete<T = any, R = AxiosResponse<T>, D = any>(
655
+ config?: AxiosRequestConfig<D, P>
656
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
657
+ delete<T = any, R = AxiosResponseDefault, D = any, P = any>(
621
658
  url: string,
622
- config?: AxiosRequestConfig<D>
623
- ): Promise<R>;
624
- head<T = any, R = AxiosResponse<T>, D = any>(
659
+ config?: AxiosRequestConfig<D, P>
660
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
661
+ head<T = any, R = AxiosResponseDefault, D = any, P = any>(
625
662
  url: string,
626
- config?: AxiosRequestConfig<D>
627
- ): Promise<R>;
628
- options<T = any, R = AxiosResponse<T>, D = any>(
663
+ config?: AxiosRequestConfig<D, P>
664
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
665
+ options<T = any, R = AxiosResponseDefault, D = any, P = any>(
629
666
  url: string,
630
- config?: AxiosRequestConfig<D>
631
- ): Promise<R>;
632
- post<T = any, R = AxiosResponse<T>, D = any>(
667
+ config?: AxiosRequestConfig<D, P>
668
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
669
+ post<T = any, R = AxiosResponseDefault, D = any, P = any>(
633
670
  url: string,
634
671
  data?: D,
635
- config?: AxiosRequestConfig<D>
636
- ): Promise<R>;
637
- put<T = any, R = AxiosResponse<T>, D = any>(
672
+ config?: AxiosRequestConfig<D, P>
673
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
674
+ put<T = any, R = AxiosResponseDefault, D = any, P = any>(
638
675
  url: string,
639
676
  data?: D,
640
- config?: AxiosRequestConfig<D>
641
- ): Promise<R>;
642
- patch<T = any, R = AxiosResponse<T>, D = any>(
677
+ config?: AxiosRequestConfig<D, P>
678
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
679
+ patch<T = any, R = AxiosResponseDefault, D = any, P = any>(
643
680
  url: string,
644
681
  data?: D,
645
- config?: AxiosRequestConfig<D>
646
- ): Promise<R>;
647
- postForm<T = any, R = AxiosResponse<T>, D = any>(
682
+ config?: AxiosRequestConfig<D, P>
683
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
684
+ postForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
648
685
  url: string,
649
686
  data?: D,
650
- config?: AxiosRequestConfig<D>
651
- ): Promise<R>;
652
- putForm<T = any, R = AxiosResponse<T>, D = any>(
687
+ config?: AxiosRequestConfig<D, P>
688
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
689
+ putForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
653
690
  url: string,
654
691
  data?: D,
655
- config?: AxiosRequestConfig<D>
656
- ): Promise<R>;
657
- patchForm<T = any, R = AxiosResponse<T>, D = any>(
692
+ config?: AxiosRequestConfig<D, P>
693
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
694
+ patchForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
658
695
  url: string,
659
696
  data?: D,
660
- config?: AxiosRequestConfig<D>
661
- ): Promise<R>;
662
- query<T = any, R = AxiosResponse<T>, D = any>(
697
+ config?: AxiosRequestConfig<D, P>
698
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
699
+ query<T = any, R = AxiosResponseDefault, D = any, P = any>(
663
700
  url: string,
664
701
  data?: D,
665
- config?: AxiosRequestConfig<D>
666
- ): Promise<R>;
702
+ config?: AxiosRequestConfig<D, P>
703
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
667
704
  }
668
705
 
669
706
  export interface AxiosInstance extends Axios {
670
- <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
671
- <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
707
+ <T = any, R = AxiosResponseDefault, D = any, P = any>(
708
+ config: AxiosRequestConfig<D, P>
709
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
710
+ <T = any, R = AxiosResponseDefault, D = any, P = any>(
711
+ url: string,
712
+ config?: AxiosRequestConfig<D, P>
713
+ ): Promise<AxiosResponseResult<T, R, D, P>>;
672
714
 
673
715
  create(config?: CreateAxiosDefaults): AxiosInstance;
674
716
  defaults: Omit<AxiosDefaults, 'headers'> & {
@@ -700,23 +742,25 @@ export function toFormData(
700
742
 
701
743
  export function formToJSON(form: GenericFormData | GenericHTMLFormElement): object;
702
744
 
703
- export function isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
745
+ export function isAxiosError<T = any, D = any, P = any>(
746
+ payload: any
747
+ ): payload is AxiosError<T, D, P>;
704
748
 
705
749
  export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
706
750
 
707
- export function isCancel<T = any>(value: any): value is CanceledError<T>;
751
+ export function isCancel<T = any, D = any, P = any>(value: any): value is CanceledError<T, D, P>;
708
752
 
709
753
  export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
710
754
 
711
- export function mergeConfig<D = any>(
712
- config1: AxiosRequestConfig<D>,
713
- config2: AxiosRequestConfig<D>
714
- ): AxiosRequestConfig<D>;
755
+ export function mergeConfig<D = any, P = any>(
756
+ config1: AxiosRequestConfig<D, P>,
757
+ config2: AxiosRequestConfig<D, P>
758
+ ): AxiosRequestConfig<D, P>;
715
759
 
716
760
  export function create(config?: CreateAxiosDefaults): AxiosInstance;
717
761
 
718
762
  export interface AxiosStatic extends AxiosInstance {
719
- Cancel: CancelStatic;
763
+ Cancel: typeof CanceledError;
720
764
  CancelToken: CancelTokenStatic;
721
765
  Axios: typeof Axios;
722
766
  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);
@@ -19,6 +19,7 @@ import platform from '../platform/index.js';
19
19
  import fromDataURI from '../helpers/fromDataURI.js';
20
20
  import stream from 'stream';
21
21
  import AxiosHeaders from '../core/AxiosHeaders.js';
22
+ import setFormDataHeaders from '../core/setFormDataHeaders.js';
22
23
  import AxiosTransformStream from '../helpers/AxiosTransformStream.js';
23
24
  import { EventEmitter } from 'events';
24
25
  import formDataToStream from '../helpers/formDataToStream.js';
@@ -33,7 +34,7 @@ import {
33
34
  progressEventDecorator,
34
35
  asyncDecorator,
35
36
  } from '../helpers/progressEventReducer.js';
36
- import estimateDataURLDecodedBytes from '../helpers/estimateDataURLDecodedBytes.js';
37
+ import { estimateDataURLBufferAllocation } from '../helpers/estimateDataURLDecodedBytes.js';
37
38
 
38
39
  const zlibOptions = {
39
40
  flush: zlib.constants.Z_SYNC_FLUSH,
@@ -54,24 +55,12 @@ const isBrotliSupported = utils.isFunction(zlib.createBrotliDecompress);
54
55
  const isZstdSupported = utils.isFunction(zlib.createZstdDecompress);
55
56
  const ACCEPT_ENCODING = 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : '');
56
57
  const ACCEPT_ENCODING_WITH_ZSTD = ACCEPT_ENCODING + (isZstdSupported ? ', zstd' : '');
58
+ const scheduleProgress =
59
+ typeof process !== 'undefined' && process.nextTick ? process.nextTick.bind(process) : utils.asap;
57
60
 
58
61
  const { http: httpFollow, https: httpsFollow } = followRedirects;
59
62
 
60
63
  const isHttps = /https:?/;
61
- const FORM_DATA_CONTENT_HEADERS = ['content-type', 'content-length'];
62
-
63
- function setFormDataHeaders(headers, formHeaders, policy) {
64
- if (policy !== 'content-only') {
65
- headers.set(formHeaders);
66
- return;
67
- }
68
-
69
- Object.entries(formHeaders).forEach(([key, val]) => {
70
- if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
71
- headers.set(key, val);
72
- }
73
- });
74
- }
75
64
 
76
65
  // Symbols used to bind a single 'error' listener to a pooled socket and track
77
66
  // the request currently owning that socket across keep-alive reuse (issue #10780).
@@ -89,6 +78,53 @@ const kAxiosInstalledTunnel = Symbol('axios.http.installedTunnel');
89
78
  // so unbounded growth is not a concern in practice.
90
79
  const tunnelingAgentCache = new Map();
91
80
  const tunnelingAgentCacheUser = new WeakMap();
81
+ // Minimum minor versions where Node's HTTP Agent supports native proxyEnv
82
+ // handling. Checking the selected agent below also covers startup modes such
83
+ // as NODE_OPTIONS=--use-env-proxy and --no-use-env-proxy precedence.
84
+ const NODE_NATIVE_ENV_PROXY_SUPPORT = {
85
+ 22: 21,
86
+ 24: 5,
87
+ };
88
+
89
+ function isNodeNativeEnvProxySupported(nodeVersion = process.versions && process.versions.node) {
90
+ if (!nodeVersion) {
91
+ return false;
92
+ }
93
+
94
+ const [major, minor] = nodeVersion.split('.').map((part) => Number(part));
95
+
96
+ if (!Number.isInteger(major) || !Number.isInteger(minor)) {
97
+ return false;
98
+ }
99
+
100
+ if (major > 24) {
101
+ return true;
102
+ }
103
+
104
+ return (
105
+ NODE_NATIVE_ENV_PROXY_SUPPORT[major] != null && minor >= NODE_NATIVE_ENV_PROXY_SUPPORT[major]
106
+ );
107
+ }
108
+
109
+ function isNodeEnvProxyEnabled(agent, nodeVersion = process.versions && process.versions.node) {
110
+ if (!isNodeNativeEnvProxySupported(nodeVersion)) {
111
+ return false;
112
+ }
113
+
114
+ const agentOptions = agent && agent.options;
115
+
116
+ return Boolean(
117
+ agentOptions &&
118
+ utils.hasOwnProp(agentOptions, 'proxyEnv') &&
119
+ agentOptions.proxyEnv != null
120
+ );
121
+ }
122
+
123
+ function getProxyEnvAgent(options, configHttpAgent, configHttpsAgent) {
124
+ return isHttps.test(options.protocol)
125
+ ? (configHttpsAgent || https.globalAgent)
126
+ : (configHttpAgent || http.globalAgent);
127
+ }
92
128
 
93
129
  function getTunnelingAgent(agentOptions, userHttpsAgent) {
94
130
  const key =
@@ -210,9 +246,10 @@ function isSameOriginRedirect(redirectOptions, requestDetails) {
210
246
  *
211
247
  * @returns {http.ClientRequestArgs}
212
248
  */
213
- function setProxy(options, configProxy, location, isRedirect, configHttpsAgent) {
249
+ function setProxy(options, configProxy, location, isRedirect, configHttpsAgent, configHttpAgent) {
214
250
  let proxy = configProxy;
215
- if (!proxy && proxy !== false) {
251
+ const proxyEnvAgent = getProxyEnvAgent(options, configHttpAgent, configHttpsAgent);
252
+ if (!proxy && proxy !== false && !isNodeEnvProxyEnabled(proxyEnvAgent)) {
216
253
  const proxyUrl = getProxyForUrl(location);
217
254
  if (proxyUrl) {
218
255
  if (!shouldBypassProxy(location)) {
@@ -363,7 +400,14 @@ function setProxy(options, configProxy, location, isRedirect, configHttpsAgent)
363
400
  options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
364
401
  // Configure proxy for redirected request, passing the original config proxy to apply
365
402
  // the exact same logic as if the redirected request was performed by axios directly.
366
- setProxy(redirectOptions, configProxy, redirectOptions.href, true, configHttpsAgent);
403
+ setProxy(
404
+ redirectOptions,
405
+ configProxy,
406
+ redirectOptions.href,
407
+ true,
408
+ configHttpsAgent,
409
+ configHttpAgent
410
+ );
367
411
  };
368
412
  }
369
413
 
@@ -475,10 +519,12 @@ export default isHttpAdapterSupported &&
475
519
  let httpVersion = own('httpVersion');
476
520
  if (httpVersion === undefined) httpVersion = 1;
477
521
  let http2Options = own('http2Options');
478
- const responseType = own('responseType');
479
- const responseEncoding = own('responseEncoding');
480
522
  const httpAgent = own('httpAgent');
481
523
  const httpsAgent = own('httpsAgent');
524
+ const configProxy = own('proxy');
525
+ const responseType = own('responseType');
526
+ const responseEncoding = own('responseEncoding');
527
+ const socketPath = own('socketPath');
482
528
  const method = own('method').toUpperCase();
483
529
  const maxRedirects = own('maxRedirects');
484
530
  const maxBodyLength = own('maxBodyLength');
@@ -603,7 +649,14 @@ export default isHttpAdapterSupported &&
603
649
 
604
650
  // Parse url
605
651
  const fullPath = buildFullPath(own('baseURL'), own('url'), own('allowAbsoluteUrls'), config);
606
- const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
652
+ // Unix-socket requests (own socketPath) commonly pass a path-only url
653
+ // like '/foo'; supply a synthetic base so new URL() can still parse it.
654
+ // Use the own-property value (not config.socketPath) so a polluted
655
+ // prototype cannot influence URL base selection.
656
+ const urlBase = socketPath
657
+ ? 'http://localhost'
658
+ : (platform.hasBrowserEnv ? platform.origin : undefined);
659
+ const parsed = new URL(fullPath, urlBase);
607
660
  const protocol = parsed.protocol || supportedProtocols[0];
608
661
 
609
662
  if (protocol === 'data:') {
@@ -611,7 +664,7 @@ export default isHttpAdapterSupported &&
611
664
  if (maxContentLength > -1) {
612
665
  // Use the exact string passed to fromDataURI (the configured url); fall back to fullPath if needed.
613
666
  const dataUrl = String(own('url') || fullPath || '');
614
- const estimated = estimateDataURLDecodedBytes(dataUrl);
667
+ const estimated = estimateDataURLBufferAllocation(dataUrl);
615
668
 
616
669
  if (estimated > maxContentLength) {
617
670
  return reject(
@@ -778,7 +831,7 @@ export default isHttpAdapterSupported &&
778
831
  data,
779
832
  progressEventDecorator(
780
833
  contentLength,
781
- progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
834
+ progressEventReducer(asyncDecorator(onUploadProgress, scheduleProgress), false, 3)
782
835
  )
783
836
  )
784
837
  );
@@ -810,11 +863,12 @@ export default isHttpAdapterSupported &&
810
863
  own('paramsSerializer')
811
864
  ).replace(/^\?/, '');
812
865
  } catch (err) {
813
- const customErr = new Error(err.message);
814
- customErr.config = config;
815
- customErr.url = own('url');
816
- customErr.exists = true;
817
- return reject(customErr);
866
+ return reject(
867
+ AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config, null, null, {
868
+ url: own('url'),
869
+ exists: true
870
+ })
871
+ );
818
872
  }
819
873
 
820
874
  headers.set(
@@ -842,7 +896,6 @@ export default isHttpAdapterSupported &&
842
896
  // cacheable-lookup integration hotfix
843
897
  !utils.isUndefined(lookup) && (options.lookup = lookup);
844
898
 
845
- const socketPath = own('socketPath');
846
899
  if (socketPath) {
847
900
  if (typeof socketPath !== 'string') {
848
901
  return reject(
@@ -880,10 +933,11 @@ export default isHttpAdapterSupported &&
880
933
  options.port = parsed.port;
881
934
  setProxy(
882
935
  options,
883
- own('proxy'),
936
+ configProxy,
884
937
  protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path,
885
938
  false,
886
- httpsAgent
939
+ httpsAgent,
940
+ httpAgent
887
941
  );
888
942
  }
889
943
  let transport;
@@ -979,10 +1033,12 @@ export default isHttpAdapterSupported &&
979
1033
  }
980
1034
  }
981
1035
 
1036
+ // Set an explicit maxBodyLength option for transports that inspect it.
1037
+ // When maxBodyLength is -1 (default/unlimited), use Infinity so
1038
+ // follow-redirects does not fall back to its own 10MB default.
982
1039
  if (maxBodyLength > -1) {
983
1040
  options.maxBodyLength = maxBodyLength;
984
1041
  } else {
985
- // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
986
1042
  options.maxBodyLength = Infinity;
987
1043
  }
988
1044
 
@@ -1013,7 +1069,7 @@ export default isHttpAdapterSupported &&
1013
1069
  transformStream,
1014
1070
  progressEventDecorator(
1015
1071
  responseLength,
1016
- progressEventReducer(asyncDecorator(onDownloadProgress), true, 3)
1072
+ progressEventReducer(asyncDecorator(onDownloadProgress, scheduleProgress), true, 3)
1017
1073
  )
1018
1074
  )
1019
1075
  );
@@ -1205,7 +1261,11 @@ export default isHttpAdapterSupported &&
1205
1261
 
1206
1262
  req.on('socket', function handleRequestSocket(socket) {
1207
1263
  // default interval of sending ack packet is 1 minute
1208
- socket.setKeepAlive(true, 1000 * 60);
1264
+ // proxy agents (e.g. agent-base) may return a generic Duplex stream
1265
+ // that doesn't have setKeepAlive, so guard before calling
1266
+ if (typeof socket.setKeepAlive === 'function') {
1267
+ socket.setKeepAlive(true, 1000 * 60);
1268
+ }
1209
1269
 
1210
1270
  // Install a single 'error' listener per socket (not per request) to avoid
1211
1271
  // accumulating listeners on pooled keep-alive sockets that get reassigned
@@ -1342,4 +1402,5 @@ export default isHttpAdapterSupported &&
1342
1402
  };
1343
1403
 
1344
1404
  export const __setProxy = setProxy;
1405
+ export const __isNodeEnvProxyEnabled = isNodeEnvProxyEnabled;
1345
1406
  export const __isSameOriginRedirect = isSameOriginRedirect;