8000 feat(http): add credentials support for fetch requests in httpResourc… · angular/angular@b6ef428 · GitHub
[go: up one dir, main page]

Skip to content

Commit b6ef428

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
feat(http): add credentials support for fetch requests in httpResource (#62390)
This commit adds support for the Fetch API's credentials option when using httpResource with the withFetch provider PR Close #62390
1 parent 1ea65b1 commit b6ef428

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-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
@@ -2524,6 +2524,7 @@ export interface HttpResourceRequest {
25242524
body?: unknown;
25252525
cache?: RequestCache | (string & {});
25262526
context?: HttpContext;
2527+
credentials?: RequestCredentials | (string & {});
25272528
headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;
25282529
keepalive?: boolean;
25292530
method?: string;

packages/common/http/src/resource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ function normalizeRequest(
286286
responseType,
287287
context: unwrappedRequest.context,
288288
transferCache: unwrappedRequest.transferCache,
289+
credentials: unwrappedRequest.credentials as RequestCredentials,
289290
timeout: unwrappedRequest.timeout,
290291
},
291292
);

packages/common/http/src/resource_api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export interface HttpResourceRequest {
8181
*/
8282
cache?: RequestCache | (string & {});
8383

84+
/**
85+
* The credentials mode of the request, which determines how cookies and other authentication information are handled.
86+
* This can affect whether credentials are sent with cross-origin requests or not.
87+
*/
88+
credentials?: RequestCredentials | (string & {});
89+
8490
/**
8591
* Indicates the relative priority of the request. This may be used by the browser to decide the order in which requests are dispatched and resources fetched.
8692
*/

packages/common/http/test/resource_spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ describe('httpResource', () => {
110110
priority: 'high',
111111
mode: 'cors',
112112
redirect: 'follow',
< 7C47 /td>113+
credentials: 'include',
113114
}),
114115
{injector: TestBed.inject(Injector)},
115116
);
@@ -124,6 +125,7 @@ describe('httpResource', () => {
124125
expect(req.request.priority).toBe('high');
125126
expect(req.request.mode).toBe('cors');
126127
expect(req.request.redirect).toBe('follow');
128+
expect(req.request.credentials).toBe('include');
127129

128130
req.flush([]);
129131

0 commit comments

Comments
 (0)
0