4

I mocking my API using Apiary.io. But somehow I cannot read any headers from response object using angularJS. And I am sure i have at least Content-Type: application/json correctly set-up by checking in firebug. Code in Angular should read headers correctly too as i can print them when sending request to somewhere else than apiary.io...

  $http.get('http://ies.apiary.io/some').then(function(response) {  
    console.log("ok",response.headers('Content-Type'));
    },function(response){console.log("err",response);});

http://plnkr.co/edit/zMO0pXGsIdJkV0fZdBdw

Almad
  • 5,753
  • 7
  • 35
  • 53
Jakub Kuchar
  • 1,665
  • 2
  • 23
  • 39

1 Answers1

5

It all boils down to a bug in firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=608735

For CORS request, firefox is not returning anything for req.getAllRequestHeaders(), although req.getRequestHeader('Content-Type') returns properly.

Either FF bug has to be fixed or Angular must work around it (as jQuery does) or you must go deeper and use XmlHttpRequest instance directly.


This was maybe also related, but probably not the core issue:


However, few days ago, Apiary.io was not setting Max-Age in CORS headers. Thus, if you had a minimal blueprint, you might have CORS pre-flight response cached and thus subsequent requests may be disallowed even if you added additional resources to your blueprint.

Max-Age is now set to 10 seconds, so it should work properly. However, depending on your browser, pre-flight cache might still affect you. Try purging it or test this app in another browser.

Almad
  • 5,753
  • 7
  • 35
  • 53
  • works fine in Chrome, however Firefox still **NOT**. Firefox was purged by clearing Cached Web Content and clearing Offline Web Content and User Data. Even private browsing mode did not help.. – Jakub Kuchar Jan 07 '13 at 14:32
  • @JakubKuchar It works for me in FF too. Could you please paste your request/response pair (or screenshot) on the OPTIONS request somewhere? Or perhaps, please create ticket through "contact support" on http://support.apiary.io/ as this looks more like apiary debugging than Angular-related issue. – Almad Jan 07 '13 at 15:56
  • i've created 2 screenshots with [Firefox](http://www.bounceapp.com/posts/new?screen_id=312065) and with [Chrominium](http://www.bounceapp.com/posts/new?screen_id=312066) using bounceapp.com hope they will be available as this was my first time using bounceapp.com – Jakub Kuchar Jan 07 '13 at 18:24
  • ticket on support.apiary.io was created – Jakub Kuchar Jan 08 '13 at 09:18
  • AngularJS issue is 3 months old https://github.com/angular/angular.js/issues/1468 – Ladislav Prskavec Jan 08 '13 at 19:27
  • @Almad, any idea how to get the actual XHR object from within an interceptor? – deitch Oct 10 '13 at 13:24
  • @deitch It should be displayed in Apiary's inspector. If not, please let us know at support@apiary.io – Almad Oct 11 '13 at 10:55