Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$http response interceptors headers

I'm sending a custom header from server in a response. In $http response interceptor I want to get this header, but the only header I could get is Content-type header. How can I resolve my problem?

Piece of my $http interceptor:

response: function (response) {
            var AuthToken = response.headers('AuthToken');
            return response || $q.when(response);
        },

AuthToken is undefined.

like image 485
Maniek Stasz Avatar asked Nov 18 '13 13:11

Maniek Stasz


1 Answers

This is a CORS issue.

The response should include Access-Control-Expose-Headers listing the specific headers you'd like to use.

e.g. Access-Control-Expose-Headers: AuthToken, AnotherCustomHeader

Depending on your server setup, this could be set site wide using an .htaccess file (Apache)

<IfModule mod_headers.c>
Header set Access-Control-Expose-Headers AuthToken,AnotherCustomHeader
</IfModule>

Or set per request in your server code (php)

header('Access-Control-Expose-Headers: AuthToken, AnotherCustomHeader');
like image 122
slamborne Avatar answered Nov 03 '22 01:11

slamborne