Search code examples
angularjshttp-headersangular-resource

How to get the complete response headers from angular resource


I'm sending a request with an Angular $resource:

myResource.get({ foo: bar }, function success(data, headers) {
            console.log("data:", data); // Prints data
            console.log("headers:", headers()); // Prints only few headers
        }, function failure(response, status) {
            // Handling failure here...
        })

But i'm only getting few headers:

{content-type: "application/json", cache-control: "no-cache, max-age=604800", expires: "Mon, 06 Apr 2015 16:21:17 GMT"}

when I want to catch the header "X-Token" (received if I check in the browser console)

Any idea to receive the complete headers list from Angular and $resource?


Solution

  • For security reasons some response headers are not exposed by default. So, you need to use Access-Control-Expose-Headers on the server, and add the extra response headers you want to return.

    Access-Control-Expose-Headers: X-Token, header-a