8000 feat(http): add keepalive support for fetch requests in httpResource by SkyZeroZx · Pull Request #61833 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

feat(http): add keepalive support for fetch requests in httpResource #61833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions goldens/public-api/common/http/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,7 @@ export interface HttpResourceRequest {
body?: unknown;
context?: HttpContext;
headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;
keepalive?: boolean;
method?: string;
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
reportProgress?: boolean;
Expand Down
1 change: 1 addition & 0 deletions packages/common/http/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ function normalizeRequest(
params,
reportProgress: unwrappedRequest.reportProgress,
withCredentials: unwrappedRequest.withCredentials,
keepalive: unwrappedRequest.keepalive,
responseType,
context: unwrappedRequest.context,
transferCache: unwrappedRequest.transferCache,
Expand Down
5 changes: 5 additions & 0 deletions packages/common/http/src/resource_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export interface HttpResourceRequest {
*/
withCredentials?: boolean;

/**
* 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.
*/
keepalive?: boolean;

/**
* Configures the server-side rendering transfer cache for this request.
*
Expand Down
4 changes: 4 additions & 0 deletions packages/common/http/test/resource_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('httpResource', () => {
'fast': 'yes',
},
withCredentials: true,
keepalive: true,
}),
{injector: TestBed.inject(Injector)},
);
Expand All @@ -114,6 +115,7 @@ describe('httpResource', () => {
expect(req.request.body).toEqual({message: 'Hello, backend!'});
expect(req.request.headers.get('X-Special')).toBe('true');
expect(req.request.withCredentials).toBe(true);
expect(req.request.keepalive).toBe(true);

req.flush([]);

Expand Down Expand Up @@ -201,6 +203,7 @@ describe('httpResource', () => {
reportProgress: true,
context: new HttpContext().set(CTX_TOKEN, 'bar'),
withCredentials: true,
keepalive: true,
transferCache: {includeHeaders: ['Y-Tag']},
}),
{
Expand All @@ -215,6 +218,7 @@ describe('httpResource', () => {
expect(req.request.withCredentials).toEqual(true);
expect(req.request.context.get(CTX_TOKEN)).toEqual('bar');
expect(req.request.reportProgress).toEqual(true);
expect(req.request.keepalive).toBe(true);
expect(req.request.transferCache).toEqual({includeHeaders: ['Y-Tag']});
});

Expand Down
Loading
0