There may be a better way to handle this problem, but as a workaround, you can create and submit a custom HttpParamsrequest and then check them in the interceptor. For example:
export class CustomHttpParams extends HttpParams {
constructor(public param1: boolean) {
super();
}
}
Using this class in an http call:
this.http.get('https://example.com', {
params: new CustomHttpParams(true)
})
And now in the interceptor:
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (request.params instanceof CustomHttpParams && request.params.param1)
request = request.clone({
setHeaders: {
'header1': 'xxxxxx'
}
});
else
request = request.clone({
setHeaders: {
'header2': 'yyyyyy'
}
});
return next.handle(request);
}
source
share