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 ?
-
Are you using Firefox? See stackoverflow.com/questions/14188662/….Dhruv Chandna– Dhruv Chandna2013-06-11 07:31:16 +00:00Commented Jun 11, 2013 at 7:31
-
No, chrome. Does the FF specific fix work for chrome ?Joy Dutta– Joy Dutta2013-06-11 15:43:28 +00:00Commented Jun 11, 2013 at 15:43
-
2Are the requests being made to a different domain or the same domain? I tested sending the request to the same domain and I am able to see the custom headers.Dhruv Chandna– Dhruv Chandna2013-06-12 04:17:46 +00:00Commented Jun 12, 2013 at 4:17
-
2You are right, the issue was due to different domains. I could finally get the custom headers to show after I made the server to send the header Access-Control-Expose-Headers.Joy Dutta– Joy Dutta2013-06-12 17:58:39 +00:00Commented Jun 12, 2013 at 17:58
-
18@JoyDutta You should create an answer, so to make this question not listed under "unanswered" tab.Ye Liu– Ye Liu2013-07-11 20:37:54 +00:00Commented Jul 11, 2013 at 20:37
|
Show 2 more comments
2 Answers
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.
5 Comments
Sam Barnum
It appears that you must specify the actual header name instead of a wildcard.
Access-Control-Expose-Headers:* does not work, but Access-Control-Expose-Headers:Etag does.chovy
this did not seem to work for me with angular's
$httpzszep
Seems that even standard headers don't work with CORS without this workaround. Had to add this: Access-Control-Expose-Headers: Content-Disposition to make the content-disposition header visible in angularjs.
Nuno Silva
This is how to do it on a rails backend: jaketrent.com/post/expose-http-headers-in-cors
Sam Barnum
You should let angular handle the cookies. You'll need to do this on the servlet side to allow the other domain to set cookies: ` resp.setHeader("Access-Control-Allow-Credentials", "true");`