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.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With