mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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
This commit is contained in:
committed by
Andrew Kushnir
parent
e9f215624f
commit
be811fee79
@@ -2784,12 +2784,14 @@ export interface HttpResourceRequest {
|
||||
context?: HttpContext;
|
||||
credentials?: RequestCredentials | (string & {});
|
||||
headers?: HttpHeaders | Record<string, string | ReadonlyArray<string>>;
|
||||
integrity?: string;
|
||||
keepalive?: boolean;
|
||||
method?: string;
|
||||
mode?: RequestMode | (string & {});
|
||||
params?: HttpParams | Record<string, string | number | boolean | ReadonlyArray<string | number | boolean>>;
|
||||
priority?: RequestPriority | (string & {});
|
||||
redirect?: RequestRedirect | (string & {});
|
||||
referrer?: string;
|
||||
reportProgress?: boolean;
|
||||
timeout?: number;
|
||||
transferCache?: {
|
||||
|
||||
@@ -287,6 +287,8 @@ function normalizeRequest(
|
||||
context: unwrappedRequest.context,
|
||||
transferCache: unwrappedRequest.transferCache,
|
||||
credentials: unwrappedRequest.credentials as RequestCredentials,
|
||||
referrer: unwrappedRequest.referrer,
|
||||
integrity: unwrappedRequest.integrity,
|
||||
timeout: unwrappedRequest.timeout,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -104,6 +104,19 @@ export interface HttpResourceRequest {
|
||||
*/
|
||||
redirect?: RequestRedirect | (string & {});
|
||||
|
||||
/**
|
||||
* The referrer of the request, which can be used to indicate the origin of the request.
|
||||
* This is useful for security and analytics purposes.
|
||||
* Value is a same-origin URL, "about:client", or the empty string, to set request's referrer.
|
||||
*/
|
||||
referrer?: string;
|
||||
|
||||
/**
|
||||
* The integrity metadata of the request, which can be used to ensure the request is made with the expected content.
|
||||
* A cryptographic hash of the resource to be fetched by request
|
||||
*/
|
||||
integrity?: string;
|
||||
|
||||
/**
|
||||
* Configures the server-side rendering transfer cache for this request.
|
||||
*
|
||||
|
||||
@@ -111,6 +111,8 @@ describe('httpResource', () => {
|
||||
mode: 'cors',
|
||||
redirect: 'follow',
|
||||
credentials: 'include',
|
||||
integrity: 'sha256-abc123',
|
||||
referrer: 'https://example.com',
|
||||
}),
|
||||
{injector: TestBed.inject(Injector)},
|
||||
);
|
||||
@@ -126,6 +128,8 @@ describe('httpResource', () => {
|
||||
expect(req.request.mode).toBe('cors');
|
||||
expect(req.request.redirect).toBe('follow');
|
||||
expect(req.request.credentials).toBe('include');
|
||||
expect(req.request.integrity).toBe('sha256-abc123');
|
||||
expect(req.request.referrer).toBe('https://example.com');
|
||||
|
||||
req.flush([]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user