8000 feat(http): add keepalive support for fetch requests in httpResource · angular/angular@30290b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 30290b1

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
feat(http): add keepalive support for fetch requests in httpResource
This commit adds support for the Fetch API's keepalive option when using httpResource with the withFetch provider
1 parent 7600bec commit 30290b1

File tree

4 files changed

+11
-0
lines changed

4 files changed

+11
-0
lines changed

goldens/public-api/common/http/index.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,7 @@ export interface HttpResourceRequest {
18721872
body?: unknown;
18731873
context?: HttpContext;
18741874
headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;
1875+
keepalive?: boolean;
18751876
method?: string;
18761877
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
18771878
reportProgress?: boolean;

packages/common/http/src/resource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ function normalizeRequest(
278278
params,
279279
reportProgress: unwrappedRequest.reportProgress,
280280
withCredentials: unwrappedRequest.withCredentials,
281+
keepalive: unwrappedRequest.keepalive,
281282
responseType,
282283
context: unwrappedRequest.context,
283284
transferCache: unwrappedRequest.transferCache,

packages/common/http/src/resource_api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export interface HttpResourceRequest {
7070
*/
7171
withCredentials?: boolean;
7272

73+
/**
74+
* 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.
75+
*/
76+
keepalive?: boolean;
77+
7378
/**
7479
* Configures the server-side rendering transfer cache for this request.
7580
*

packages/common/http/test/resource_spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ describe('httpResource', () => {
105105
'fast': 'yes',
106106
},
107107
withCredentials: true,
108+
keepalive: true,
108109
}),
109110
{injector: TestBed.inject(Injector)},
110111
);
@@ -114,6 +115,7 @@ describe('httpResource', () => {
114115
expect(req.request.body).toEqual({message: 'Hello, backend!'});
115116
expect(req.request.headers.get('X-Special')).toBe('true');
116117
expect(req.request.withCredentials).toBe(true);
118+
expect(req.request.keepalive).toBe(true);
117119

118120
req.flush([]);
119121

@@ -201,6 +203,7 @@ describe('httpResource', () => {
201203
reportProgress: true,
202204
context: new HttpContext().set(CTX_TOKEN, 'bar'),
203205
withCredentials: true,
206+
keepalive: true,
204207
transferCache: {includeHeaders: ['Y-Tag']},
205208
}),
206209
{
@@ -215,6 +218,7 @@ describe('httpResource', () => {
215218
expect(req.request.withCredentials).toEqual(true);
216219
expect(req.request.context.get(CTX_TOKEN)).toEqual('bar');
217220
expect(req.request.reportProgress).toEqual(true);
221+
expect(req.request.keepalive).toBe(true);
218222
expect(req.request.transferCache).toEqual({includeHeaders: ['Y-Tag']});
219223
});
220224

0 commit comments

Comments
 (0)
0