3

I would like to get the 'X-Total-Count' response header of a RESTful API. While trying to get the header in the query callback function of my ngResource 'User', it seems that $http ignores a lot of the reponse headers.

These are the response headers of my request:

Access-Control-Allow-Origin: *
Cache-Control: max-age=0, private, must-revalidate
Connection: close
Content-Encoding: gzip
Content-Type: application/json; charset=utf-8
Date: Fri, 17 Oct 2014 11:13:26 GMT
Link: <http://xxxx.xxx/user?page=2>; rel="next"
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Total-Count: 32

Here I'm querying the set of users:

User.query({
    page: $scope.pagingOptions.currentPage, 
    limit: $scope.pagingOptions.pageSize
}, function(users, responseHeaders) {
    console.log(responseHeaders());
    console.log(responseHeaders('X-Total-Count'));
});

That's the result of the console:

Object { cache-control="max-age=0, private, must-revalidate", content-type="application/json; charset=utf-8"}
null

So why the $http's responseHeaders() function turns only 2 of 10 header properties?

2
  • 4
    You also need Access-Control-Expose-Headers: X-Foo as described here: stackoverflow.com/questions/17038436/… Commented Oct 17, 2014 at 11:41
  • I have exactly the same problem, using a $http.get().success() in my case, even with adding the Access-Control-Expose-Headers: X-Total-Count in my API service response, i'm unable to get my header in angular ... Have you found any solution so far ? Commented Dec 8, 2014 at 10:42

1 Answer 1

0

Are you sure you are not doing cross origin resource sharing?

see 7.1.1 Handling a Response to a Cross-Origin Request

That specification forbids access to any response header field other except the simple response header fields (i.e. Cache-Control, Content-Type, ...)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.