I'm having a problem with AngularJS's $http service not returning all of the headers from the API I'm polling. Here's what I've got:

$http({
    method: 'POST',
    withCredentials: true,
    url: 'http://api.mydomain.com/query',
    data: JSON.stringify(parameters)
})
.success(function(data, status, headers, config){
    ... // setting some scope parameters based on data
    console.log(headers());
})

I can tell through the network tab in Chrome that a bunch of response headers are being returned by the API (I'm particularly interested in the X-Pagination-Total-Items header).

Here's a screenshot of the network tab from the request: Chrome's Network Panel

But the console.log statement above (which should output all headers) only returns two: Console Log...missing headers!

Any idea what's going on? How do I actually access all of the headers coming back from the AJAX call?

Thanks,

-Nate

share|improve this question
    
Which headers can't you access? (Also, consider prepending them with X-) – Benjamin Gruenbaum Feb 7 '14 at 18:59
    
Benjamin, I'm trying to get X-Pagination-Total-Items. I'm wondering if it's a CORS issue and whether Access-Control-Expose-Headers can't take a wildcard... – Nathan Rutman Feb 7 '14 at 19:05
up vote 41 down vote accepted

Turns out that the Access-Control-Expose-Headers cannot accept a wildcard. We needed to specify exactly which headers the client should have access to, and then it worked.

share|improve this answer
4  
I spent HOURS trying to figure this out. Thank you, thank you, a million times thank you – Eli Gassert Aug 28 '14 at 19:25
    
@EliGassert, glad it helped you as well. One of the great things about StackOverflow! :-) – Nathan Rutman Sep 2 '14 at 13:43
    
Oh my god.. I too forgot to add these headers to my CORS filter. No wonder I could see them in the browser response but not in the AngularJS headers() call output. – Stephane Nov 5 '14 at 20:51
    
Is this on the backend issue? – Tim Lieberman May 13 '15 at 21:07
3  
Yes, this is a backend issue. You should configure your web server to send back desired header fields. Wildcards are not supported so this won't work; Access-Control-Expose-Headers:* Instead you should provide exact header field i.e. Access-Control-Expose-Headers:Etag – Sarpdoruk Tahmaz Nov 28 '15 at 20:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.