In an Angular application, I use an interceptor to inject the token (when needed) into the request headers. I also need it to modify the Content-Type header to the appropriate one. By default, it must be application/json, but there is a call that needs to upload a ZIP file, so I want to let the Content-Type header as is (for these cases, it's something like: Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryvamnUWepE840OEuq). I use this code:
intercept (req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
let usr = this.userService.getActualUser();
let confirmationToken = '';
let credentials = false;
let contentType = 'application/json';
// Check if the incoming request has an specific content type header
if (req.headers.has('Content-Type')) {
contentType = req.headers.get('Content-Type');
}
// ETC
}
The problem is that req.headers.has('Content-Type') always returns false, so I'm setting the wrong type and the call fails. What am I doing wrong?
Thanks in advance!