Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 594
tezqa Avatar asked Oct 20 '22 15:10

tezqa


1 Answers

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
like image 137
Muhammad Reda Avatar answered Oct 22 '22 23:10

Muhammad Reda