Problem
I am trying to set a header named Cookie. I do this using an interceptor, so that it gets done on every request.
Code
@Injectable
export class HeaderInterceptor implements HttpInterceptor {
constructor(private: authService: AuthenticationService) {}
intercept(reg: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return from(this.authService.getAuthentication()).pipe(
switchMap((token) => {
const headers = req.headers
.set(TOKEN, "someToken")
.set("Cookie", "someCookie")
.append("Content-Type", "application/json")
.append("Accept", "application/json");
const requestClone = req.clone({ headers, withCredentials: true });
return next.handle(requestClone);
})
);
}
}
What happens
I always get:
Attempt to set a forbidden header was denied: Cookie
So what can I do here? I also tried setting withCredentials: true
directly on every request which also did not work. Is there any other way?