Reading response headers when using $http of Angularjs

Angularjs

Angularjs Problem Overview


I am using $http to make an api call which is sending some custom header like X-Foo. However I can't yet figure out how to read them. Inside the $http({...}).success(function (data, status, headers, config) {...}) function, headers is a function that should give me a hash of all headers but it only shows the header content-type. Is there a way to get the response headers ?

Angularjs Solutions


Solution 1 - Angularjs

The custom headers will be visible in same domain. However, for the crossdomain situation, the server has to send Access-Control-Expose-Headers: X-Foo, ... header to make the custom headers visible.

Solution 2 - Angularjs

Spring 4.0+ provide @CrossOrigin annotation which has following parameters

  1. origins = list of Comma separated origin.
  2. exposedHeaders = list ofcomma separated count custom parameters.

example

@CrossOrigin(origins = "*", exposedHeaders ="X-Total-Count")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJoy DuttaView Question on Stackoverflow
Solution 1 - AngularjsPabloView Answer on Stackoverflow
Solution 2 - AngularjsHarsh MaheswariView Answer on Stackoverflow