feat(http): add keepalive support for fetch requests (#60621)

This commit adds support for the Fetch API's keepalive option when using HttpClient with the withFetch provider.

The change includes:
- Added keepalive to HttpRequestInit interface
- Modified FetchBackend to pass the option
- Added some unit test

PR Close #60621
This commit is contained in:
SkyZeroZx 2025-03-28 19:32:28 -05:00 committed by Miles Malerba
parent e711f99d81
commit ccc5cc068f
9 changed files with 324 additions and 6 deletions

View file

@ -21,6 +21,8 @@ export const enum RuntimeErrorCode {
// (undocumented)
JSONP_WRONG_RESPONSE_TYPE = 2811,
// (undocumented)
KEEPALIVE_NOT_SUPPORTED_WITH_XHR = 2813,
// (undocumented)
MISSING_JSONP_MODULE = -2800,
// (undocumented)
NOT_USING_FETCH_BACKEND_IN_SSR = 2801,

View file

@ -50,6 +50,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<ArrayBuffer>;
delete(url: string, options: {
@ -60,6 +61,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<Blob>;
delete(url: string, options: {
@ -70,6 +72,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<string>;
delete(url: string, options: {
@ -80,6 +83,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpEvent<ArrayBuffer>>;
delete(url: string, options: {
@ -90,6 +94,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpEvent<Blob>>;
delete(url: string, options: {
@ -100,6 +105,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpEvent<string>>;
delete(url: string, options: {
@ -110,6 +116,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpEvent<Object>>;
delete<T>(url: string, options: {
@ -120,6 +127,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpEvent<T>>;
delete(url: string, options: {
@ -130,6 +138,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpResponse<ArrayBuffer>>;
delete(url: string, options: {
@ -140,6 +149,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpResponse<Blob>>;
delete(url: string, options: {
@ -150,6 +160,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpResponse<string>>;
delete(url: string, options: {
@ -160,6 +171,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpResponse<Object>>;
delete<T>(url: string, options: {
@ -170,6 +182,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<HttpResponse<T>>;
delete(url: string, options?: {
@ -180,6 +193,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<Object>;
delete<T>(url: string, options?: {
@ -190,6 +204,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
}): Observable<T>;
get(url: string, options: {
@ -200,6 +215,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -212,6 +228,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -224,6 +241,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -236,6 +254,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -248,6 +267,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -260,6 +280,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -272,6 +293,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -284,6 +306,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -296,6 +319,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -308,6 +332,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -320,6 +345,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -332,6 +358,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -344,6 +371,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -356,6 +384,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -368,6 +397,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -380,6 +410,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -392,6 +423,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -404,6 +436,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -416,6 +449,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -428,6 +462,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -440,6 +475,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -452,6 +488,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -464,6 +501,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -476,6 +514,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -488,6 +527,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -500,6 +540,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -512,6 +553,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -524,6 +566,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -536,6 +579,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -548,6 +592,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -562,6 +607,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<ArrayBuffer>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -571,6 +617,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<Blob>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -580,6 +627,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<string>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -589,6 +637,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -598,6 +647,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<Blob>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -607,6 +657,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<string>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -616,6 +667,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<Object>>;
options<T>(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -625,6 +677,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<T>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -634,6 +687,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -643,6 +697,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Blob>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -652,6 +707,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<string>>;
options(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -661,6 +717,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Object>>;
options<T>(url: string, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -670,6 +727,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<T>>;
options(url: string, options?: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -679,6 +737,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<Object>;
options<T>(url: string, options?: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -688,6 +747,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<T>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -697,6 +757,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<ArrayBuffer>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -706,6 +767,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<Blob>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -715,6 +777,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<string>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -724,6 +787,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -733,6 +797,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<Blob>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -742,6 +807,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<string>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -751,6 +817,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<Object>>;
patch<T>(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -760,6 +827,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<T>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -769,6 +837,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -778,6 +847,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Blob>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -787,6 +857,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<string>>;
patch(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -796,6 +867,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Object>>;
patch<T>(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -805,6 +877,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<T>>;
patch(url: string, body: any | null, options?: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -814,6 +887,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<Object>;
patch<T>(url: string, body: any | null, options?: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -823,6 +897,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<T>;
post(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -832,6 +907,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -844,6 +920,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -856,6 +933,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -868,6 +946,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -880,6 +959,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -892,6 +972,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -904,6 +985,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -916,6 +998,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -928,6 +1011,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -940,6 +1024,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -952,6 +1037,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -964,6 +1050,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -976,6 +1063,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -988,6 +1076,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1000,6 +1089,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1012,6 +1102,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<ArrayBuffer>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1021,6 +1112,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<Blob>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1030,6 +1122,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<string>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1039,6 +1132,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<ArrayBuffer>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1048,6 +1142,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<Blob>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1057,6 +1152,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<string>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1066,6 +1162,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<Object>>;
put<T>(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1075,6 +1172,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpEvent<T>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1084,6 +1182,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<ArrayBuffer>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1093,6 +1192,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Blob>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1102,6 +1202,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<string>>;
put(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1111,6 +1212,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Object>>;
put<T>(url: string, body: any | null, options: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1120,6 +1222,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<T>>;
put(url: string, body: any | null, options?: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1129,6 +1232,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<Object>;
put<T>(url: string, body: any | null, options?: {
headers?: HttpHeaders | Record<string, string | string[]>;
@ -1138,6 +1242,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<T>;
request<R>(req: HttpRequest<any>): Observable<HttpEvent<R>>;
request(method: string, url: string, options: {
@ -1149,6 +1254,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1162,6 +1268,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1175,6 +1282,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1188,6 +1296,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1201,6 +1310,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1214,6 +1324,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1227,6 +1338,7 @@ export class HttpClient {
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1240,6 +1352,7 @@ export class HttpClient {
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1253,6 +1366,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1266,6 +1380,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1279,6 +1394,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1292,6 +1408,7 @@ export class HttpClient {
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
}): Observable<HttpResponse<Object>>;
request<R>(method: string, url: string, options: {
body?: any;
@ -1302,6 +1419,7 @@ export class HttpClient {
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1315,6 +1433,7 @@ export class HttpClient {
responseType?: 'json';
reportProgress?: boolean;
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1328,6 +1447,7 @@ export class HttpClient {
responseType?: 'json';
reportProgress?: boolean;
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1341,6 +1461,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1569,6 +1690,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1580,6 +1702,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
});
constructor(method: 'POST', url: string, body: T | null, init?: {
headers?: HttpHeaders;
@ -1588,6 +1711,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1599,6 +1723,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
});
constructor(method: string, url: string, body: T | null, init?: {
headers?: HttpHeaders;
@ -1607,6 +1732,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1622,6 +1748,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {
includeHeaders?: string[];
} | boolean;
@ -1642,6 +1769,7 @@ export class HttpRequest<T> {
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
keepalive?: boolean;
withCredentials?: boolean;
transferCache?: {
includeHeaders?: string[];
@ -1659,6 +1787,7 @@ export class HttpRequest<T> {
readonly context: HttpContext;
detectContentTypeHeader(): string | null;
readonly headers: HttpHeaders;
readonly keepalive: boolean;
readonly method: string;
readonly params: HttpParams;
readonly reportProgress: boolean;

View file

@ -39,6 +39,7 @@ function addBody<T>(
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
body: T | null,
@ -53,6 +54,7 @@ function addBody<T>(
responseType: options.responseType,
withCredentials: options.withCredentials,
transferCache: options.transferCache,
keepalive: options.keepalive,
};
}
@ -145,6 +147,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<ArrayBuffer>;
@ -173,6 +176,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Blob>;
@ -201,6 +205,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<string>;
@ -230,6 +235,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -259,6 +265,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Blob>>;
@ -288,6 +295,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<string>>;
@ -317,6 +325,7 @@ export class HttpClient {
| Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<any>>;
@ -346,6 +355,7 @@ export class HttpClient {
| Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<R>>;
@ -374,6 +384,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -401,6 +412,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Blob>>;
@ -429,6 +441,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<string>>;
@ -458,6 +471,7 @@ export class HttpClient {
| Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Object>>;
@ -485,6 +499,7 @@ export class HttpClient {
| Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<R>>;
@ -513,6 +528,7 @@ export class HttpClient {
responseType?: 'json';
reportProgress?: boolean;
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Object>;
@ -541,6 +557,7 @@ export class HttpClient {
responseType?: 'json';
reportProgress?: boolean;
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<R>;
@ -568,6 +585,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<any>;
@ -612,6 +630,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
} = {},
): Observable<any> {
@ -643,7 +662,6 @@ export class HttpClient {
params = new HttpParams({fromObject: options.params} as HttpParamsOptions);
}
}
// Construct the request.
req = new HttpRequest(first, url!, options.body !== undefined ? options.body : null, {
headers,
@ -654,9 +672,9 @@ export class HttpClient {
responseType: options.responseType || 'json',
withCredentials: options.withCredentials,
transferCache: options.transferCache,
keepalive: options.keepalive,
});
}
// Start with an Observable.of() the initial request, and run the handler (which
// includes all interceptors) inside a concatMap(). This way, the handler runs
// inside an Observable chain, which causes interceptors to be re-run on every
@ -765,6 +783,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<ArrayBuffer>;
@ -790,6 +809,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<Blob>;
@ -815,6 +835,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<string>;
@ -841,6 +862,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -867,6 +889,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpEvent<Blob>>;
@ -893,6 +916,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpEvent<string>>;
@ -919,6 +943,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpEvent<Object>>;
@ -945,6 +970,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpEvent<T>>;
@ -970,6 +996,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -995,6 +1022,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpResponse<Blob>>;
@ -1020,6 +1048,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpResponse<string>>;
@ -1046,6 +1075,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpResponse<Object>>;
@ -1071,6 +1101,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<HttpResponse<T>>;
@ -1096,6 +1127,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<Object>;
@ -1121,6 +1153,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
},
): Observable<T>;
@ -1146,6 +1179,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
body?: any | null;
} = {},
): Observable<any> {
@ -1173,6 +1207,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<ArrayBuffer>;
@ -1198,6 +1233,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Blob>;
@ -1223,6 +1259,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<string>;
@ -1249,6 +1286,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -1274,6 +1312,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Blob>>;
@ -1299,6 +1338,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<string>>;
@ -1324,6 +1364,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Object>>;
@ -1349,6 +1390,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<T>>;
@ -1375,6 +1417,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -1401,6 +1444,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Blob>>;
@ -1427,6 +1471,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<string>>;
@ -1453,6 +1498,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Object>>;
@ -1479,6 +1525,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<T>>;
@ -1505,6 +1552,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Object>;
@ -1530,6 +1578,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<T>;
@ -1551,6 +1600,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
} = {},
): Observable<any> {
@ -1578,6 +1628,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<ArrayBuffer>;
@ -1604,6 +1655,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Blob>;
@ -1629,6 +1681,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<string>;
@ -1655,6 +1708,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -1681,6 +1735,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Blob>>;
@ -1707,6 +1762,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<string>>;
@ -1733,6 +1789,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Object>>;
@ -1759,6 +1816,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<T>>;
@ -1785,6 +1843,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -1811,6 +1870,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Blob>>;
@ -1837,6 +1897,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<string>>;
@ -1863,6 +1924,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Object>>;
@ -1889,6 +1951,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<T>>;
@ -1915,6 +1978,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Object>;
@ -1941,6 +2005,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<T>;
@ -1964,6 +2029,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
} = {},
): Observable<any> {
@ -2041,6 +2107,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<ArrayBuffer>;
@ -2065,6 +2132,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<Blob>;
@ -2089,6 +2157,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<string>;
@ -2114,6 +2183,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -2139,6 +2209,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<Blob>>;
@ -2164,6 +2235,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<string>>;
@ -2189,6 +2261,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<Object>>;
@ -2214,6 +2287,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<T>>;
@ -2239,6 +2313,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -2264,6 +2339,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Blob>>;
@ -2289,6 +2365,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<string>>;
@ -2314,6 +2391,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Object>>;
@ -2339,6 +2417,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<T>>;
@ -2364,6 +2443,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<Object>;
@ -2388,6 +2468,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<T>;
@ -2410,6 +2491,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
} = {},
): Observable<any> {
return this.request<any>('OPTIONS', url, options as any);
@ -2438,6 +2520,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<ArrayBuffer>;
@ -2464,6 +2547,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<Blob>;
@ -2490,6 +2574,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<string>;
@ -2518,6 +2603,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -2545,6 +2631,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<Blob>>;
@ -2572,6 +2659,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<string>>;
@ -2599,6 +2687,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<Object>>;
@ -2626,6 +2715,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<T>>;
@ -2653,6 +2743,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -2680,6 +2771,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Blob>>;
@ -2707,6 +2799,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<string>>;
@ -2734,6 +2827,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Object>>;
@ -2761,6 +2855,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<T>>;
@ -2788,6 +2883,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<Object>;
@ -2815,6 +2911,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<T>;
@ -2836,6 +2933,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
} = {},
): Observable<any> {
return this.request<any>('PATCH', url, addBody(options, body));
@ -2864,6 +2962,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<ArrayBuffer>;
@ -2891,6 +2990,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Blob>;
@ -2918,6 +3018,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<string>;
@ -2946,6 +3047,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -2973,6 +3075,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Blob>>;
@ -3001,6 +3104,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<string>>;
@ -3029,6 +3133,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<Object>>;
@ -3057,6 +3162,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpEvent<T>>;
@ -3085,6 +3191,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -3113,6 +3220,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Blob>>;
@ -3141,6 +3249,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<string>>;
@ -3169,6 +3278,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<Object>>;
@ -3198,6 +3308,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<HttpResponse<T>>;
@ -3225,6 +3336,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<Object>;
@ -3253,6 +3365,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
): Observable<T>;
@ -3276,6 +3389,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
} = {},
): Observable<any> {
@ -3305,6 +3419,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<ArrayBuffer>;
@ -3331,6 +3446,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<Blob>;
@ -3357,6 +3473,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<string>;
@ -3384,6 +3501,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<ArrayBuffer>>;
@ -3411,6 +3529,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<Blob>>;
@ -3438,6 +3557,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<string>>;
@ -3465,6 +3585,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<Object>>;
@ -3492,6 +3613,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpEvent<T>>;
@ -3519,6 +3641,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'arraybuffer';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<ArrayBuffer>>;
@ -3546,6 +3669,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'blob';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Blob>>;
@ -3573,6 +3697,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType: 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<string>>;
@ -3600,6 +3725,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<Object>>;
@ -3627,6 +3753,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<HttpResponse<T>>;
@ -3653,6 +3780,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<Object>;
@ -3679,6 +3807,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'json';
withCredentials?: boolean;
keepalive?: boolean;
},
): Observable<T>;
@ -3701,6 +3830,7 @@ export class HttpClient {
reportProgress?: boolean;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
} = {},
): Observable<any> {
return this.request<any>('PUT', url, addBody(options, body));

View file

@ -24,4 +24,5 @@ export const enum RuntimeErrorCode {
JSONP_WRONG_METHOD = 2810,
JSONP_WRONG_RESPONSE_TYPE = 2811,
JSONP_HEADERS_NOT_SUPPORTED = 2812,
KEEPALIVE_NOT_SUPPORTED_WITH_XHR = 2813,
}

View file

@ -88,7 +88,6 @@ export class FetchBackend implements HttpBackend {
): Promise<void> {
const init = this.createRequestInit(request);
let response;
try {
// Run fetch outside of Angular zone.
// This is due to Node.js fetch implementation (Undici) which uses a number of setTimeouts to check if
@ -282,6 +281,7 @@ export class FetchBackend implements HttpBackend {
method: req.method,
headers,
credentials,
keepalive: req.keepalive,
};
}

View file

@ -23,6 +23,7 @@ interface HttpRequestInit {
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
keepalive?: boolean;
}
/**
@ -163,6 +164,11 @@ export class HttpRequest<T> {
*/
readonly withCredentials: boolean = false;
/**
* When using the fetch implementation and set to `true`, the browser will not abort the associated request if the page that initiated it is unloaded before the request is complete.
*/
readonly keepalive: boolean = false;
/**
* The expected response type of the server.
*
@ -208,6 +214,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
/**
* This property accepts either a boolean to enable/disable transferring cache for eligible
* requests performed using `HttpClient`, or an object, which allows to configure cache
@ -229,6 +236,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
);
constructor(
@ -242,6 +250,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
/**
* This property accepts either a boolean to enable/disable transferring cache for eligible
* requests performed using `HttpClient`, or an object, which allows to configure cache
@ -264,6 +273,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
},
);
constructor(
@ -277,6 +287,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
/**
* This property accepts either a boolean to enable/disable transferring cache for eligible
* requests performed using `HttpClient`, or an object, which allows to configure cache
@ -300,6 +311,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
}
| null,
@ -310,6 +322,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
},
) {
@ -334,7 +347,7 @@ export class HttpRequest<T> {
// Normalize reportProgress and withCredentials.
this.reportProgress = !!options.reportProgress;
this.withCredentials = !!options.withCredentials;
this.keepalive = !!options.keepalive;
// Override default response type of 'json' if one is provided.
if (!!options.responseType) {
this.responseType = options.responseType;
@ -478,6 +491,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: T | null;
method?: string;
@ -491,6 +505,7 @@ export class HttpRequest<T> {
reportProgress?: boolean;
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
keepalive?: boolean;
withCredentials?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: V | null;
@ -507,6 +522,7 @@ export class HttpRequest<T> {
params?: HttpParams;
responseType?: 'arraybuffer' | 'blob' | 'json' | 'text';
withCredentials?: boolean;
keepalive?: boolean;
transferCache?: {includeHeaders?: string[]} | boolean;
body?: any | null;
method?: string;
@ -520,7 +536,7 @@ export class HttpRequest<T> {
const method = update.method || this.method;
const url = update.url || this.url;
const responseType = update.responseType || this.responseType;
const keepalive = update.keepalive ?? this.keepalive;
// Carefully handle the transferCache to differentiate between
// `false` and `undefined` in the update args.
const transferCache = update.transferCache ?? this.transferCache;
@ -571,6 +587,7 @@ export class HttpRequest<T> {
responseType,
withCredentials,
transferCache,
keepalive,
});
}
}

View file

@ -7,7 +7,11 @@
*/
import {XhrFactory} from '../../index';
import {Injectable, ɵRuntimeError as RuntimeError} from '@angular/core';
import {
Injectable,
ɵRuntimeError as RuntimeError,
ɵformatRuntimeError as formatRuntimeError,
} from '@angular/core';
import {from, Observable, Observer, of} from 'rxjs';
import {switchMap} from 'rxjs/operators';
@ -79,6 +83,15 @@ export class HttpXhrBackend implements HttpBackend {
);
}
if (req.keepalive && ngDevMode) {
console.warn(
formatRuntimeError(
RuntimeErrorCode.KEEPALIVE_NOT_SUPPORTED_WITH_XHR,
`Angular detected that a \`HttpClient\` request with the \`keepalive\` option was sent using XHR, which does not support it. To use the \`keepalive\` option, enable Fetch API support by passing \`withFetch()\` as an argument to \`provideHttpClient()\`.`,
),
);
}
// Check whether this factory has a special function to load an XHR implementation
// for various non-browser environments. We currently limit it to only `ServerXhr`
// class, which needs to load an XHR implementation.

View file

@ -291,6 +291,20 @@ describe('FetchBackend', async () => {
fetchMock.mockAbortEvent();
});
it('should pass keepalive option to fetch', () => {
const req = new HttpRequest('GET', '/test', {keepalive: true});
backend.handle(req).subscribe();
expect(fetchSpy).toHaveBeenCalledWith(
'/test',
jasmine.objectContaining({
keepalive: true,
}),
);
fetchMock.mockFlush(HttpStatusCode.Ok, 'OK');
});
describe('progress events', () => {
it('are emitted for download progress', (done) => {
backend

View file

@ -64,6 +64,13 @@ describe('HttpRequest', () => {
const req = new HttpRequest('GET', TEST_URL);
expect(req.responseType).toBe('json');
});
it('should allow setting keepalive option', () => {
const req = new HttpRequest('GET', '/test', {keepalive: true});
expect(req.keepalive).toBe(true);
const req2 = new HttpRequest('GET', '/test', {keepalive: false});
expect(req2.keepalive).toBe(false);
});
});
describe('clone() copies the request', () => {
const headers = new HttpHeaders({
@ -77,6 +84,7 @@ describe('HttpRequest', () => {
responseType: 'text',
withCredentials: true,
transferCache: true,
keepalive: true,
});
it('in the base case', () => {
const clone = req.clone();
@ -89,6 +97,7 @@ describe('HttpRequest', () => {
expect(clone.context).toBe(context);
expect(clone.transferCache).toBe(true);
expect(clone.keepalive).toBe(true);
});
it('and updates the url', () => {
expect(req.clone({url: '/changed'}).url).toBe('/changed');
@ -106,6 +115,9 @@ describe('HttpRequest', () => {
it('and updates the transferCache', () => {
expect(req.clone({transferCache: false}).transferCache).toBe(false);
});
it('and updates the keepalive', () => {
expect(req.clone({keepalive: false}).keepalive).toBe(false);
});
});
describe('content type detection', () => {
const baseReq = new HttpRequest('POST', '/test', null);