Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 8 - HttpInterceptor - read response headers

I am missing http headers in a response from my HttpInterceptor. I can get a body but not headers. Please see attached output and my code.

@Injectable()
export class ApiVersionInterceptor implements HttpInterceptor {
    intercept(
        req: import("@angular/common/http").HttpRequest<any>,
        next: import("@angular/common/http").HttpHandler
    ): import("rxjs").Observable<import("@angular/common/http").HttpEvent<any>> {
        return next.handle(req).pipe(
            tap(httpEvent=>{
                // Skip request
                if(httpEvent.type === 0){
                    return;
                }
                console.log("response: ", httpEvent);
            })

        );
    }
}

enter image description here

like image 894
Lopuch Avatar asked Dec 13 '22 09:12

Lopuch


1 Answers

Wohoo I fixed my problem.

It is not Angular problem but server problem. I need to add another header:

"access-control-expose-headers": "mintargetapiversion"

Angular ignores custom headers if they are not specified in "access-control-expose-header"

like image 89
Lopuch Avatar answered Dec 29 '22 09:12

Lopuch