( ...features: HttpFeature<HttpFeatureKind>[] )
| 97 | * @see {@link withXhr} |
| 98 | */ |
| 99 | export function provideHttpClient( |
| 100 | ...features: HttpFeature<HttpFeatureKind>[] |
| 101 | ): EnvironmentProviders { |
| 102 | if (ngDevMode) { |
| 103 | const featureKinds = new Set(features.map((f) => f.ɵkind)); |
| 104 | if ( |
| 105 | featureKinds.has(HttpFeatureKind.NoXsrfProtection) && |
| 106 | featureKinds.has(HttpFeatureKind.CustomXsrfConfiguration) |
| 107 | ) { |
| 108 | throw new Error( |
| 109 | ngDevMode |
| 110 | ? `Configuration error: found both withXsrfConfiguration() and withNoXsrfProtection() in the same call to provideHttpClient(), which is a contradiction.` |
| 111 | : '', |
| 112 | ); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | const providers: Provider[] = [ |
| 117 | HttpClient, |
| 118 | FetchBackend, |
| 119 | HttpInterceptorHandler, |
| 120 | {provide: HttpHandler, useExisting: HttpInterceptorHandler}, |
| 121 | { |
| 122 | provide: HttpBackend, |
| 123 | useFactory: () => { |
| 124 | return inject(FetchBackend); |
| 125 | }, |
| 126 | }, |
| 127 | { |
| 128 | provide: HTTP_INTERCEPTOR_FNS, |
| 129 | useValue: xsrfInterceptorFn, |
| 130 | multi: true, |
| 131 | }, |
| 132 | ]; |
| 133 | |
| 134 | for (const feature of features) { |
| 135 | providers.push(...feature.ɵproviders); |
| 136 | } |
| 137 | |
| 138 | return makeEnvironmentProviders(providers); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Adds one or more functional-style HTTP interceptors to the configuration of the `HttpClient` |
no test coverage detected
searching dependent graphs…