Angular HttpClient missing response headers
The headers in an HttpResponse object are lazy-loaded, so headers
will appear to be empty until you force the values to be loaded. Try calling response.headers.keys()
to see all available header names. By the way, this also forces all values to be loaded into the map response.headers.headers
.
CORS requests only expose 6 safelisted headers : Cache-Control
Content-Language
Content-Type
Expires
Last-Modified
& Pragma
.
In order to access custom headers with a CORS request, the server has to explicitly whitelist them. This can be done by sending the response header: Access-Control-Expose-Headers
For example:
Access-Control-Expose-Headers: X-Total-Count, X-Paging-PageSize
MDN Source