Created
September 18, 2018 10:12
-
-
Save wKoza/990629c9e99aafbfb49d2bc9c74b5014 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable() | |
export class HttpInterceptingHandler implements HttpHandler { | |
private chain: HttpHandler|null = null; | |
constructor(private backend: HttpBackend, private injector: Injector) {} | |
handle(req: HttpRequest<any>): Observable<HttpEvent<any>> { | |
if (this.chain === null) { | |
const interceptors = this.injector.get(HTTP_INTERCEPTORS, []); | |
this.chain = interceptors.reduceRight( | |
(next, interceptor) => new HttpInterceptorHandler(next, interceptor), this.backend); | |
} | |
return this.chain.handle(req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment