fix(platform-server): avoid dependency cycle when using http interceptor (#24229)
Fixes #23023. When a HTTP Interceptor injects HttpClient it causes a DI cycle. This fix is to use Injector to lazily inject HTTP_INTERCEPTORS while setting up the HttpHandler on the server so as to break the cycle. PR Close #24229
This commit is contained in:

committed by
Victor Berchet

parent
68a799e950
commit
60aa943e2d
@ -8,10 +8,10 @@
|
||||
|
||||
const xhr2: any = require('xhr2');
|
||||
|
||||
import {Injectable, Optional, Provider} from '@angular/core';
|
||||
import {Injectable, Injector, Optional, Provider, InjectFlags} from '@angular/core';
|
||||
import {BrowserXhr, Connection, ConnectionBackend, Http, ReadyState, Request, RequestOptions, Response, XHRBackend, XSRFStrategy} from '@angular/http';
|
||||
|
||||
import {HttpEvent, HttpRequest, HttpHandler, HttpInterceptor, HTTP_INTERCEPTORS, HttpBackend, XhrFactory, ɵinterceptingHandler as interceptingHandler} from '@angular/common/http';
|
||||
import {HttpEvent, HttpRequest, HttpHandler, HttpInterceptor, HTTP_INTERCEPTORS, HttpBackend, XhrFactory, ɵHttpInterceptingHandler as HttpInterceptingHandler} from '@angular/common/http';
|
||||
|
||||
import {Observable, Observer, Subscription} from 'rxjs';
|
||||
|
||||
@ -156,9 +156,8 @@ export function httpFactory(xhrBackend: XHRBackend, options: RequestOptions) {
|
||||
return new Http(macroBackend, options);
|
||||
}
|
||||
|
||||
export function zoneWrappedInterceptingHandler(
|
||||
backend: HttpBackend, interceptors: HttpInterceptor[] | null) {
|
||||
const realBackend: HttpBackend = interceptingHandler(backend, interceptors);
|
||||
export function zoneWrappedInterceptingHandler(backend: HttpBackend, injector: Injector) {
|
||||
const realBackend: HttpBackend = new HttpInterceptingHandler(backend, injector);
|
||||
return new ZoneClientBackend(realBackend);
|
||||
}
|
||||
|
||||
@ -168,6 +167,6 @@ export const SERVER_HTTP_PROVIDERS: Provider[] = [
|
||||
{provide: XhrFactory, useClass: ServerXhr}, {
|
||||
provide: HttpHandler,
|
||||
useFactory: zoneWrappedInterceptingHandler,
|
||||
deps: [HttpBackend, [new Optional(), HTTP_INTERCEPTORS]]
|
||||
deps: [HttpBackend, Injector]
|
||||
}
|
||||
];
|
||||
|
Reference in New Issue
Block a user