axios 1.18.1 → 1.20.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.
- package/CHANGELOG.md +62 -0
- package/README.md +297 -5
- package/dist/axios.js +728 -170
- package/dist/axios.min.js +3 -3
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +871 -188
- package/dist/esm/axios.js +871 -188
- package/dist/esm/axios.min.js +2 -2
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +1037 -225
- package/index.d.cts +102 -74
- package/index.d.ts +100 -68
- package/lib/adapters/fetch.js +64 -11
- package/lib/adapters/http.js +140 -67
- package/lib/adapters/xhr.js +52 -3
- package/lib/core/Axios.js +43 -20
- package/lib/core/AxiosError.js +33 -2
- package/lib/core/AxiosHeaders.js +124 -1
- package/lib/core/InterceptorManager.js +107 -8
- package/lib/core/buildFullPath.js +41 -15
- package/lib/core/dispatchRequest.js +8 -2
- package/lib/core/mergeConfig.js +19 -4
- package/lib/core/methodList.js +17 -0
- package/lib/core/setFormDataHeaders.js +27 -0
- package/lib/defaults/index.js +2 -1
- package/lib/env/data.js +1 -1
- package/lib/helpers/Http2Sessions.js +2 -0
- package/lib/helpers/HttpStatusCode.js +12 -1
- package/lib/helpers/combineURLs.js +11 -3
- package/lib/helpers/composeSignals.js +12 -1
- package/lib/helpers/estimateDataURLDecodedBytes.js +115 -54
- package/lib/helpers/formDataToJSON.js +11 -5
- package/lib/helpers/fromDataURI.js +5 -4
- package/lib/helpers/normalizeURLForProtocolCheck.js +24 -0
- package/lib/helpers/parseHeaders.js +5 -3
- package/lib/helpers/progressEventReducer.js +4 -4
- package/lib/helpers/resolveConfig.js +5 -17
- package/lib/helpers/shouldBypassProxy.js +300 -5
- package/lib/helpers/throttle.js +3 -2
- package/lib/helpers/toFormData.js +17 -23
- package/lib/platform/node/classes/Buffer.js +11 -0
- package/lib/utils.js +151 -18
- package/package.json +21 -19
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
|
}
|
|
@@ -33,6 +35,7 @@ export class AxiosHeaders {
|
|
|
33
35
|
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
|
|
34
36
|
set(headers?: Iterable<[string, AxiosHeaderValue]>, rewrite?: boolean): AxiosHeaders;
|
|
35
37
|
|
|
38
|
+
get(headerName: string, parser: typeof AxiosHeaders.parseParameters): AxiosHeaderParameters;
|
|
36
39
|
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
|
37
40
|
get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
|
|
38
41
|
|
|
@@ -54,6 +57,8 @@ export class AxiosHeaders {
|
|
|
54
57
|
|
|
55
58
|
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
|
56
59
|
|
|
60
|
+
static parseParameters(value: AxiosHeaderValue): AxiosHeaderParameters;
|
|
61
|
+
|
|
57
62
|
static accessor(header: string | string[]): AxiosHeaders;
|
|
58
63
|
|
|
59
64
|
static concat(
|
|
@@ -209,14 +214,18 @@ export enum HttpStatusCode {
|
|
|
209
214
|
Gone = 410,
|
|
210
215
|
LengthRequired = 411,
|
|
211
216
|
PreconditionFailed = 412,
|
|
217
|
+
/** @deprecated Use `ContentTooLarge` instead. */
|
|
212
218
|
PayloadTooLarge = 413,
|
|
219
|
+
ContentTooLarge = 413,
|
|
213
220
|
UriTooLong = 414,
|
|
214
221
|
UnsupportedMediaType = 415,
|
|
215
222
|
RangeNotSatisfiable = 416,
|
|
216
223
|
ExpectationFailed = 417,
|
|
217
224
|
ImATeapot = 418,
|
|
218
225
|
MisdirectedRequest = 421,
|
|
226
|
+
/** @deprecated Use `UnprocessableContent` instead. */
|
|
219
227
|
UnprocessableEntity = 422,
|
|
228
|
+
UnprocessableContent = 422,
|
|
220
229
|
Locked = 423,
|
|
221
230
|
FailedDependency = 424,
|
|
222
231
|
TooEarly = 425,
|
|
@@ -236,6 +245,7 @@ export enum HttpStatusCode {
|
|
|
236
245
|
LoopDetected = 508,
|
|
237
246
|
NotExtended = 510,
|
|
238
247
|
NetworkAuthenticationRequired = 511,
|
|
248
|
+
WebServerReturnsAnUnknownError = 520,
|
|
239
249
|
WebServerIsDown = 521,
|
|
240
250
|
ConnectionTimedOut = 522,
|
|
241
251
|
OriginIsUnreachable = 523,
|
|
@@ -335,13 +345,13 @@ export interface ParamEncoder {
|
|
|
335
345
|
(value: any, defaultEncoder: (value: any) => any): any;
|
|
336
346
|
}
|
|
337
347
|
|
|
338
|
-
export interface CustomParamsSerializer {
|
|
339
|
-
(params:
|
|
348
|
+
export interface CustomParamsSerializer<P = Record<string, any>> {
|
|
349
|
+
(params: P, options?: ParamsSerializerOptions<P>): string;
|
|
340
350
|
}
|
|
341
351
|
|
|
342
|
-
export interface ParamsSerializerOptions extends SerializerOptions {
|
|
352
|
+
export interface ParamsSerializerOptions<P = Record<string, any>> extends SerializerOptions {
|
|
343
353
|
encode?: ParamEncoder;
|
|
344
|
-
serialize?: CustomParamsSerializer
|
|
354
|
+
serialize?: CustomParamsSerializer<P>;
|
|
345
355
|
}
|
|
346
356
|
|
|
347
357
|
type MaxUploadRate = number;
|
|
@@ -378,7 +388,7 @@ export interface LookupAddressEntry {
|
|
|
378
388
|
|
|
379
389
|
export type LookupAddress = string | LookupAddressEntry;
|
|
380
390
|
|
|
381
|
-
export interface AxiosRequestConfig<D = any> {
|
|
391
|
+
export interface AxiosRequestConfig<D = any, P = any> {
|
|
382
392
|
url?: string;
|
|
383
393
|
method?: StringLiteralsOrString<Method>;
|
|
384
394
|
baseURL?: string;
|
|
@@ -386,8 +396,10 @@ export interface AxiosRequestConfig<D = any> {
|
|
|
386
396
|
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
|
387
397
|
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
|
388
398
|
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
|
389
|
-
params?:
|
|
390
|
-
paramsSerializer?:
|
|
399
|
+
params?: P;
|
|
400
|
+
paramsSerializer?:
|
|
401
|
+
| ParamsSerializerOptions<unknown extends P ? Record<string, any> : P>
|
|
402
|
+
| CustomParamsSerializer<unknown extends P ? Record<string, any> : P>;
|
|
391
403
|
data?: D;
|
|
392
404
|
timeout?: Milliseconds;
|
|
393
405
|
timeoutErrorMessage?: string;
|
|
@@ -455,7 +467,7 @@ export interface AxiosRequestConfig<D = any> {
|
|
|
455
467
|
) => Promise<
|
|
456
468
|
[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress
|
|
457
469
|
>);
|
|
458
|
-
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
|
|
470
|
+
withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig<D, P>) => boolean | undefined);
|
|
459
471
|
parseReviver?: (this: any, key: string, value: any, context?: { source?: string }) => any;
|
|
460
472
|
fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
|
|
461
473
|
httpVersion?: 1 | 2;
|
|
@@ -468,9 +480,9 @@ export interface AxiosRequestConfig<D = any> {
|
|
|
468
480
|
}
|
|
469
481
|
|
|
470
482
|
// Alias
|
|
471
|
-
export type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
|
|
483
|
+
export type RawAxiosRequestConfig<D = any, P = any> = AxiosRequestConfig<D, P>;
|
|
472
484
|
|
|
473
|
-
export interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
|
|
485
|
+
export interface InternalAxiosRequestConfig<D = any, P = any> extends AxiosRequestConfig<D, P> {
|
|
474
486
|
headers: AxiosRequestHeaders;
|
|
475
487
|
}
|
|
476
488
|
|
|
@@ -489,49 +501,52 @@ export interface HeadersDefaults {
|
|
|
489
501
|
query?: RawAxiosRequestHeaders;
|
|
490
502
|
}
|
|
491
503
|
|
|
492
|
-
export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
|
504
|
+
export interface AxiosDefaults<D = any, P = any> extends Omit<AxiosRequestConfig<D, P>, 'headers'> {
|
|
493
505
|
headers: HeadersDefaults;
|
|
494
506
|
}
|
|
495
507
|
|
|
496
|
-
export interface CreateAxiosDefaults<D = any> extends Omit<
|
|
508
|
+
export interface CreateAxiosDefaults<D = any, P = any> extends Omit<
|
|
509
|
+
AxiosRequestConfig<D, P>,
|
|
510
|
+
'headers'
|
|
511
|
+
> {
|
|
497
512
|
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
|
498
513
|
}
|
|
499
514
|
|
|
500
|
-
export interface AxiosResponse<T = any, D = any, H = {}> {
|
|
515
|
+
export interface AxiosResponse<T = any, D = any, H = {}, P = any> {
|
|
501
516
|
data: T;
|
|
502
517
|
status: number;
|
|
503
518
|
statusText: string;
|
|
504
519
|
headers: (H & RawAxiosResponseHeaders) | AxiosResponseHeaders;
|
|
505
|
-
config: InternalAxiosRequestConfig<D>;
|
|
520
|
+
config: InternalAxiosRequestConfig<D, P>;
|
|
506
521
|
request?: any;
|
|
507
522
|
}
|
|
508
523
|
|
|
509
|
-
export class AxiosError<T = unknown, D = any> extends Error {
|
|
524
|
+
export class AxiosError<T = unknown, D = any, P = any> extends Error {
|
|
510
525
|
constructor(
|
|
511
526
|
message?: string,
|
|
512
527
|
code?: string,
|
|
513
|
-
config?: InternalAxiosRequestConfig<D>,
|
|
528
|
+
config?: InternalAxiosRequestConfig<D, P>,
|
|
514
529
|
request?: any,
|
|
515
|
-
response?: AxiosResponse<T, D>
|
|
530
|
+
response?: AxiosResponse<T, D, {}, P>
|
|
516
531
|
);
|
|
517
532
|
|
|
518
|
-
config?: InternalAxiosRequestConfig<D>;
|
|
533
|
+
config?: InternalAxiosRequestConfig<D, P>;
|
|
519
534
|
code?: string;
|
|
520
535
|
request?: any;
|
|
521
|
-
response?: AxiosResponse<T, D>;
|
|
536
|
+
response?: AxiosResponse<T, D, {}, P>;
|
|
522
537
|
isAxiosError: boolean;
|
|
523
538
|
status?: number;
|
|
524
539
|
toJSON: () => object;
|
|
525
540
|
cause?: Error;
|
|
526
541
|
event?: BrowserProgressEvent;
|
|
527
|
-
static from<T = unknown, D = any>(
|
|
542
|
+
static from<T = unknown, D = any, P = any>(
|
|
528
543
|
error: Error | unknown,
|
|
529
544
|
code?: string,
|
|
530
|
-
config?: InternalAxiosRequestConfig<D>,
|
|
545
|
+
config?: InternalAxiosRequestConfig<D, P>,
|
|
531
546
|
request?: any,
|
|
532
|
-
response?: AxiosResponse<T, D>,
|
|
547
|
+
response?: AxiosResponse<T, D, {}, P>,
|
|
533
548
|
customProps?: object
|
|
534
|
-
): AxiosError<T, D>;
|
|
549
|
+
): AxiosError<T, D, P>;
|
|
535
550
|
static readonly ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
|
|
536
551
|
static readonly ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
|
|
537
552
|
static readonly ERR_BAD_OPTION = 'ERR_BAD_OPTION';
|
|
@@ -548,13 +563,21 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|
|
548
563
|
static readonly ETIMEDOUT = 'ETIMEDOUT';
|
|
549
564
|
}
|
|
550
565
|
|
|
551
|
-
export class CanceledError<T> extends AxiosError<T> {
|
|
552
|
-
constructor(message?: string, config?: InternalAxiosRequestConfig, request?: any);
|
|
566
|
+
export class CanceledError<T, D = any, P = any> extends AxiosError<T, D, P> {
|
|
567
|
+
constructor(message?: string, config?: InternalAxiosRequestConfig<D, P>, request?: any);
|
|
553
568
|
readonly name: 'CanceledError';
|
|
554
569
|
__CANCEL__?: boolean;
|
|
555
570
|
}
|
|
556
571
|
|
|
557
|
-
|
|
572
|
+
declare const axiosResponseDefault: unique symbol;
|
|
573
|
+
|
|
574
|
+
type AxiosResponseDefault = typeof axiosResponseDefault;
|
|
575
|
+
|
|
576
|
+
type AxiosResponseResult<T, R, D, P> = R extends AxiosResponseDefault
|
|
577
|
+
? AxiosResponse<T, D, {}, P>
|
|
578
|
+
: R;
|
|
579
|
+
|
|
580
|
+
export type AxiosPromise<T = any, D = any, P = any> = Promise<AxiosResponse<T, D, {}, P>>;
|
|
558
581
|
|
|
559
582
|
export interface CancelStatic {
|
|
560
583
|
new (message?: string): Cancel;
|
|
@@ -628,63 +651,70 @@ export class Axios {
|
|
|
628
651
|
response: AxiosInterceptorManager<AxiosResponse>;
|
|
629
652
|
};
|
|
630
653
|
getUri(config?: AxiosRequestConfig): string;
|
|
631
|
-
request<T = any, R =
|
|
632
|
-
|
|
654
|
+
request<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
655
|
+
config: AxiosRequestConfig<D, P>
|
|
656
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
657
|
+
get<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
633
658
|
url: string,
|
|
634
|
-
config?: AxiosRequestConfig<D>
|
|
635
|
-
): Promise<R
|
|
636
|
-
delete<T = any, R =
|
|
659
|
+
config?: AxiosRequestConfig<D, P>
|
|
660
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
661
|
+
delete<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
637
662
|
url: string,
|
|
638
|
-
config?: AxiosRequestConfig<D>
|
|
639
|
-
): Promise<R
|
|
640
|
-
head<T = any, R =
|
|
663
|
+
config?: AxiosRequestConfig<D, P>
|
|
664
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
665
|
+
head<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
641
666
|
url: string,
|
|
642
|
-
config?: AxiosRequestConfig<D>
|
|
643
|
-
): Promise<R
|
|
644
|
-
options<T = any, R =
|
|
667
|
+
config?: AxiosRequestConfig<D, P>
|
|
668
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
669
|
+
options<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
645
670
|
url: string,
|
|
646
|
-
config?: AxiosRequestConfig<D>
|
|
647
|
-
): Promise<R
|
|
648
|
-
post<T = any, R =
|
|
671
|
+
config?: AxiosRequestConfig<D, P>
|
|
672
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
673
|
+
post<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
649
674
|
url: string,
|
|
650
675
|
data?: D,
|
|
651
|
-
config?: AxiosRequestConfig<D>
|
|
652
|
-
): Promise<R
|
|
653
|
-
put<T = any, R =
|
|
676
|
+
config?: AxiosRequestConfig<D, P>
|
|
677
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
678
|
+
put<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
654
679
|
url: string,
|
|
655
680
|
data?: D,
|
|
656
|
-
config?: AxiosRequestConfig<D>
|
|
657
|
-
): Promise<R
|
|
658
|
-
patch<T = any, R =
|
|
681
|
+
config?: AxiosRequestConfig<D, P>
|
|
682
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
683
|
+
patch<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
659
684
|
url: string,
|
|
660
685
|
data?: D,
|
|
661
|
-
config?: AxiosRequestConfig<D>
|
|
662
|
-
): Promise<R
|
|
663
|
-
postForm<T = any, R =
|
|
686
|
+
config?: AxiosRequestConfig<D, P>
|
|
687
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
688
|
+
postForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
664
689
|
url: string,
|
|
665
690
|
data?: D,
|
|
666
|
-
config?: AxiosRequestConfig<D>
|
|
667
|
-
): Promise<R
|
|
668
|
-
putForm<T = any, R =
|
|
691
|
+
config?: AxiosRequestConfig<D, P>
|
|
692
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
693
|
+
putForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
669
694
|
url: string,
|
|
670
695
|
data?: D,
|
|
671
|
-
config?: AxiosRequestConfig<D>
|
|
672
|
-
): Promise<R
|
|
673
|
-
patchForm<T = any, R =
|
|
696
|
+
config?: AxiosRequestConfig<D, P>
|
|
697
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
698
|
+
patchForm<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
674
699
|
url: string,
|
|
675
700
|
data?: D,
|
|
676
|
-
config?: AxiosRequestConfig<D>
|
|
677
|
-
): Promise<R
|
|
678
|
-
query<T = any, R =
|
|
701
|
+
config?: AxiosRequestConfig<D, P>
|
|
702
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
703
|
+
query<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
679
704
|
url: string,
|
|
680
705
|
data?: D,
|
|
681
|
-
config?: AxiosRequestConfig<D>
|
|
682
|
-
): Promise<R
|
|
706
|
+
config?: AxiosRequestConfig<D, P>
|
|
707
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
683
708
|
}
|
|
684
709
|
|
|
685
710
|
export interface AxiosInstance extends Axios {
|
|
686
|
-
<T = any, R =
|
|
687
|
-
|
|
711
|
+
<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
712
|
+
config: AxiosRequestConfig<D, P>
|
|
713
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
714
|
+
<T = any, R = AxiosResponseDefault, D = any, P = any>(
|
|
715
|
+
url: string,
|
|
716
|
+
config?: AxiosRequestConfig<D, P>
|
|
717
|
+
): Promise<AxiosResponseResult<T, R, D, P>>;
|
|
688
718
|
|
|
689
719
|
create(config?: CreateAxiosDefaults): AxiosInstance;
|
|
690
720
|
defaults: Omit<AxiosDefaults, 'headers'> & {
|
|
@@ -716,18 +746,20 @@ export function toFormData(
|
|
|
716
746
|
|
|
717
747
|
export function formToJSON(form: GenericFormData | GenericHTMLFormElement): object;
|
|
718
748
|
|
|
719
|
-
export function isAxiosError<T = any, D = any
|
|
749
|
+
export function isAxiosError<T = any, D = any, P = any>(
|
|
750
|
+
payload: any
|
|
751
|
+
): payload is AxiosError<T, D, P>;
|
|
720
752
|
|
|
721
753
|
export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
|
722
754
|
|
|
723
|
-
export function isCancel<T = any>(value: any): value is CanceledError<T>;
|
|
755
|
+
export function isCancel<T = any, D = any, P = any>(value: any): value is CanceledError<T, D, P>;
|
|
724
756
|
|
|
725
757
|
export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
|
726
758
|
|
|
727
|
-
export function mergeConfig<D = any>(
|
|
728
|
-
config1: AxiosRequestConfig<D>,
|
|
729
|
-
config2: AxiosRequestConfig<D>
|
|
730
|
-
): AxiosRequestConfig<D>;
|
|
759
|
+
export function mergeConfig<D = any, P = any>(
|
|
760
|
+
config1: AxiosRequestConfig<D, P>,
|
|
761
|
+
config2: AxiosRequestConfig<D, P>
|
|
762
|
+
): AxiosRequestConfig<D, P>;
|
|
731
763
|
|
|
732
764
|
export function create(config?: CreateAxiosDefaults): AxiosInstance;
|
|
733
765
|
|
package/lib/adapters/fetch.js
CHANGED
|
@@ -17,6 +17,18 @@ import { toByteStringHeaderObject } from '../helpers/sanitizeHeaderValue.js';
|
|
|
17
17
|
|
|
18
18
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
19
19
|
|
|
20
|
+
const DEFAULT_REQUEST_OPTIONS = {
|
|
21
|
+
cache: 'default',
|
|
22
|
+
redirect: 'follow',
|
|
23
|
+
referrer: 'about:client',
|
|
24
|
+
referrerPolicy: '',
|
|
25
|
+
mode: 'cors',
|
|
26
|
+
integrity: '',
|
|
27
|
+
keepalive: false,
|
|
28
|
+
priority: 'auto',
|
|
29
|
+
window: null,
|
|
30
|
+
};
|
|
31
|
+
|
|
20
32
|
const { isFunction } = utils;
|
|
21
33
|
|
|
22
34
|
/**
|
|
@@ -67,9 +79,7 @@ const maybeWithAuthCredentials = (url) => {
|
|
|
67
79
|
|
|
68
80
|
const factory = (env) => {
|
|
69
81
|
const globalObject =
|
|
70
|
-
utils.global !== undefined && utils.global !== null
|
|
71
|
-
? utils.global
|
|
72
|
-
: globalThis;
|
|
82
|
+
utils.global !== undefined && utils.global !== null ? utils.global : globalThis;
|
|
73
83
|
const { ReadableStream, TextEncoder } = globalObject;
|
|
74
84
|
|
|
75
85
|
env = utils.merge.call(
|
|
@@ -208,6 +218,7 @@ const factory = (env) => {
|
|
|
208
218
|
fetchOptions,
|
|
209
219
|
maxContentLength,
|
|
210
220
|
maxBodyLength,
|
|
221
|
+
maxRedirects,
|
|
211
222
|
} = resolveConfig(config);
|
|
212
223
|
|
|
213
224
|
const hasMaxContentLength = utils.isNumber(maxContentLength) && maxContentLength > -1;
|
|
@@ -258,7 +269,7 @@ const factory = (env) => {
|
|
|
258
269
|
const password = utils.getSafeProp(configAuth, 'password') || '';
|
|
259
270
|
auth = {
|
|
260
271
|
username,
|
|
261
|
-
password
|
|
272
|
+
password,
|
|
262
273
|
};
|
|
263
274
|
}
|
|
264
275
|
|
|
@@ -270,7 +281,7 @@ const factory = (env) => {
|
|
|
270
281
|
const urlPassword = decodeURIComponentSafe(parsedURL.password);
|
|
271
282
|
auth = {
|
|
272
283
|
username: urlUsername,
|
|
273
|
-
password: urlPassword
|
|
284
|
+
password: urlPassword,
|
|
274
285
|
};
|
|
275
286
|
}
|
|
276
287
|
|
|
@@ -344,7 +355,9 @@ const factory = (env) => {
|
|
|
344
355
|
(onUploadProgress || mustEnforceStreamBody)
|
|
345
356
|
) {
|
|
346
357
|
requestContentLength =
|
|
347
|
-
requestContentLength == null
|
|
358
|
+
requestContentLength == null
|
|
359
|
+
? await resolveBodyLength(headers, data)
|
|
360
|
+
: requestContentLength;
|
|
348
361
|
|
|
349
362
|
// A declared length of 0 is only trusted to skip the wrap when we are
|
|
350
363
|
// not enforcing a stream limit (which must not rely on that header).
|
|
@@ -357,7 +370,10 @@ const factory = (env) => {
|
|
|
357
370
|
|
|
358
371
|
let contentTypeHeader;
|
|
359
372
|
|
|
360
|
-
if (
|
|
373
|
+
if (
|
|
374
|
+
utils.isFormData(data) &&
|
|
375
|
+
(contentTypeHeader = _request.headers.get('content-type'))
|
|
376
|
+
) {
|
|
361
377
|
headers.setContentType(contentTypeHeader);
|
|
362
378
|
}
|
|
363
379
|
|
|
@@ -420,20 +436,57 @@ const factory = (env) => {
|
|
|
420
436
|
// Set User-Agent header if not already set (fetch defaults to 'node' in Node.js)
|
|
421
437
|
headers.set('User-Agent', 'axios/' + VERSION, false);
|
|
422
438
|
|
|
423
|
-
const
|
|
424
|
-
|
|
439
|
+
const safeFetchOptions =
|
|
440
|
+
fetchOptions == null ? fetchOptions : Object.assign(Object.create(null), fetchOptions);
|
|
441
|
+
|
|
442
|
+
if (safeFetchOptions) {
|
|
443
|
+
// These options are owned by Axios and are already reflected in the
|
|
444
|
+
// resolved Request passed to fetch.
|
|
445
|
+
delete safeFetchOptions.body;
|
|
446
|
+
delete safeFetchOptions.headers;
|
|
447
|
+
delete safeFetchOptions.method;
|
|
448
|
+
delete safeFetchOptions.signal;
|
|
449
|
+
delete safeFetchOptions.duplex;
|
|
450
|
+
delete safeFetchOptions.credentials;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const resolvedOptions = Object.assign(Object.create(null), safeFetchOptions, {
|
|
425
454
|
signal: composedSignal,
|
|
426
455
|
method: method.toUpperCase(),
|
|
427
456
|
headers: toByteStringHeaderObject(headers.normalize()),
|
|
428
457
|
body: data,
|
|
429
458
|
duplex: 'half',
|
|
430
459
|
credentials: isCredentialsSupported ? withCredentials : undefined,
|
|
431
|
-
};
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
if (isRequestSupported) {
|
|
463
|
+
utils.forEach(DEFAULT_REQUEST_OPTIONS, (value, key) => {
|
|
464
|
+
if (resolvedOptions[key] === undefined) {
|
|
465
|
+
resolvedOptions[key] = value;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
if (resolvedOptions.signal === undefined) {
|
|
470
|
+
resolvedOptions.signal = null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (resolvedOptions.body === undefined) {
|
|
474
|
+
resolvedOptions.body = null;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (maxRedirects === 0) {
|
|
479
|
+
resolvedOptions.redirect = 'manual';
|
|
480
|
+
|
|
481
|
+
if (safeFetchOptions) {
|
|
482
|
+
safeFetchOptions.redirect = 'manual';
|
|
483
|
+
}
|
|
484
|
+
}
|
|
432
485
|
|
|
433
486
|
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
434
487
|
|
|
435
488
|
let response = await (isRequestSupported
|
|
436
|
-
? _fetch(request,
|
|
489
|
+
? _fetch(request, safeFetchOptions)
|
|
437
490
|
: _fetch(url, resolvedOptions));
|
|
438
491
|
|
|
439
492
|
const responseHeaders = AxiosHeaders.from(response.headers);
|