-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Open
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP ClientfeatureIssue that requests a new featureIssue that requests a new feature
Milestone
Description
Which @angular/* package(s) are relevant/related to the feature request?
common
Description
I would like to be able to provide my own implementation of FetchFactory
.
Currently the angular codebase already has an internal solution used for testing only:
https://github.com/angular/angular/blob/main/packages/common/http/src/fetch.ts#L339
The use case where this is relevant is with cloudflare workers under the same account and http request between them is forbidden and you can only use it through service binding to directly call the worker's fetch function.
At the moment I'm "forced" to copy paste the whole FetchBackend
class to be able to modify the fetch implementation.
Proposed solution
{
provide: FetchFactory,
useClass: CustomFetchFactory,
}
Example implementation
export class CustomFetchFactory implements FetchFactory {
private bindings = inject<Bindings>(REQUEST_CONTEXT);
fetch(url: string, init?: RequestInit): Promise<Response> {
if (this.bindings?.CF_WORKER && url.includes('cf-worker-under-same-account')) {
return this.bindings.CF_WORKER.fetch(new Request(url, init));
}
return globalThis.fetch(url, init);
}
}
Alternatives considered
none
alfaproject, BoyeMagnus, eneajaho and SkyZeroZx
Metadata
Metadata
Assignees
Labels
area: common/httpIssues related to HTTP and HTTP ClientIssues related to HTTP and HTTP ClientfeatureIssue that requests a new featureIssue that requests a new feature