jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 270 forks source link

xdomain responses do not work well with recent Angular updates due to changes in httpBackend #52

Closed bvaughn closed 10 years ago

bvaughn commented 10 years ago

We've recently discovered a serious IE8/IE9 defect between Angular 1.2.10+ and the xdomain library. Initially I thought it to be an Angular defect and reported it as a bug. After further investigation though I realized that the cause of the issue was the interplay between Angular's $httpBackend (line 94), the xdomain's initialization of facade.

Angular checks for response vs responseText like this:

response = ('response' in xhr) ? xhr.response : xhr.responseText;

However, the xdomain lib always initializes a response attribute (even if it's null for IE) and so this causes any values in responseText data to be overlooked.

Fortunately the fix for this is a simple 2-parter.

1) Line 326: do not initialize response to null.

facade.response = null;

2) Change writeBody to be more like this:

  writeBody = function() {
    if ( response.hasOwnProperty('text') ) {
      facade.responseText = response.text;
    } else if ( response.hasOwnProperty('xml') ) {
      facade.responseXML = response.xml;
    } else {
      facade.response = response.data || null;
    }
  };
jpillora commented 10 years ago

Hey @bvaughn thanks for the debugging effort. XHook attempts to perfectly implement XMLHttpRequest2, however as you can see, it's not quite there yet. I've setup a basic saucelabs test for XDomain. Still need to add saucelabs to XHook and add more libraries tests. However time is hard to find >.< Will try to incorporate your fix in soon :)

bvaughn commented 10 years ago

No problem @jpillora ! Thanks for supporting this library. It's very handy.

bvaughn commented 10 years ago

Dude! Thanks for such a speedy turn-around.

jpillora commented 10 years ago

No worries

On Sat, Mar 8, 2014 at 11:08 AM, Brian Vaughn notifications@github.comwrote:

Dude! Thanks for such a speedy turn-around.

Reply to this email directly or view it on GitHubhttps://github.com/jpillora/xdomain/issues/52#issuecomment-37081452 .