Search code examples
angularheaderresponse

How to get all the headers from an Angular 2 response?


Response in Chrome Dev Tools

The response headers I see in Chrome Dev tools don't match the ones that Angular 2 is showing in the Chrome console.

Only Content Type Showing Up

Only the Content-Type header is showing up after having executed:

this.http.get(tempUrl).map(res=>{
      console.log("csrf received");
      console.log(res);
})

Solution

  • Only a certain list of "safe" headers are exposed by default (to Javascript). This is for security reasons. This list is as follows

    • Cache-Control
    • Content-Language
    • Content-Type
    • Expires
    • Last-Modified
    • Pragma

    In order to expose other headers, the server should send the access control header Access-Control-Expose-Headers, listing all the headers it wants to expose.

    Access-Control-Expose-Headers: Content-Length, X-CSRF-Token