The header object is available in the success callback but not the .then() callback. Is there some other way to work promise-based that I am not aware of that gives you access to the headers?
It's worth noting that the success callback for get, query and other methods gets passed in the response that came from the server as well as $http header getter function, so one could rewrite the above example and get access to http headers as:
var User = $resource('/user/:userId', {userId:'@id'}); User.get({userId:123}, function(u, getResponseHeaders){ u.abc = true; u.$save(function(u, putResponseHeaders) { //u => saved user object //putResponseHeaders => $http header getter }); });
Be nice to have:
var User = $resource('/user/:userId', {userId:'@id'});
var CurrentUser.get({userId:123})
CurrentUser.then(function(u, getResponseHeaders){
headers = getResponseHeaders();
});
Sorry, I don't think it can happen as the then "callbacks" can have only argument. The reason for this is that those "callbacks" correspond to the return value / exception from synchronous programming and you can't return multiple results / throw multiple exceptions from a regular function.
Closing for now as introducing what you are asking for would be confusing to people used to promises.
It would be nice to inject the headers into the response object somehow. So it could be retrieved like: .then(function(data){data.headers()})
Most helpful comment
It would be nice to inject the headers into the response object somehow. So it could be retrieved like: .then(function(data){data.headers()})