Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be811fe

Browse files
SkyZeroZxAndrewKushnir
authored andcommitted
feat(http): add referrer & integrity support for fetch requests in httpResource (#62461)
This commit adds support for the Fetch API's referrer & integrity options when using httpResource with the withFetch provider PR Close #62461
1 parent e9f2156 commit be811fe

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,12 +2784,14 @@ export interface HttpResourceRequest {
27842784
context?: HttpContext;
27852785
credentials?: RequestCredentials | (string & {});
27862786
headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;
2787+
integrity?: string;
27872788
keepalive?: boolean;
27882789
method?: string;
27892790
mode?: RequestMode | (string & {});
27902791
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
27912792
priority?: RequestPriority | (string & {});
27922793
redirect?: RequestRedirect | (string & {});
2794+
referrer?: string;
27932795
reportProgress?: boolean;
27942796
timeout?: number;
27952797
transferCache?: {

‎packages/common/http/src/resource.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ function normalizeRequest(
287287
context: unwrappedRequest.context,
288288
transferCache: unwrappedRequest.transferCache,
289289
credentials: unwrappedRequest.credentials as RequestCredentials,
290+
referrer: unwrappedRequest.referrer,
291+
integrity: unwrappedRequest.integrity,
290292
timeout: unwrappedRequest.timeout,
291293
},
292294
);

‎packages/common/http/src/resource_api.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ export interface HttpResourceRequest {
104104
*/
105105
redirect?: RequestRedirect | (string & {});
106106

107+
/**
108+
* The referrer of the request, which can be used to indicate the origin of the request.
109+
* This is useful for security and analytics purposes.
110+
* Value is a same-origin URL, "about:client", or the empty string, to set request's referrer.
111+
*/
112+
referrer?: string;
113+
114+
/**
115+
* The integrity metadata of the request, which can be used to ensure the request is made with the expected content.
116+
* A cryptographic hash of the resource to be fetched by request
117+
*/
118+
integrity?: string;
119+
107120
/**
108121
* Configures the server-side rendering transfer cache for this request.
109122
*

‎packages/common/http/test/resource_spec.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ describe('httpResource', () => {
111111
mode: 'cors',
112112
redirect: 'follow',
113113
credentials: 'include',
114+
integrity: 'sha256-abc123',
115+
referrer: 'https://example.com',
114116
}),
115117
{injector: TestBed.inject(Injector)},
116118
);
@@ -126,6 +128,8 @@ describe('httpResource', () => {
126128
expect(req.request.mode).toBe('cors');
127129
expect(req.request.redirect).toBe('follow');
128130
expect(req.request.credentials).toBe('include');
131+
expect(req.request.integrity).toBe('sha256-abc123');
132+
expect(req.request.referrer).toBe('https://example.com');
129133

130134
req.flush([]);
131135

0 commit comments

Comments
 (0)