jpillora / xdomain

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

Bug: Preflight OPTIONS Request When Unnecessary #137

Closed sgarbesi closed 9 years ago

sgarbesi commented 9 years ago

Please see this plnkr example:

http://plnkr.co/edit/9YfiPAKo0yagfLhYRmSu

If you remove the <script> include for the xdomain.js library there's no preflight OPTIONS request necessary. Something with the library is triggering/enforcing it, even when it's not needed.

jpillora commented 9 years ago

I can't see the proxy file in your example?

sgarbesi commented 9 years ago

@jpillora Even without the proxy it shouldn't force the options request?

jpillora commented 9 years ago

Confirmed this is a bug, though it's not with XDomain, it's with XHook. Still not sure why it's happening.

jpillora commented 9 years ago

Created smaller example here http://plnkr.co/edit/5qtYBpBE4GEJlViL6iCH?p=preview

kawazoe commented 9 years ago

This issue is causing some requests to fail with a CORS error on firefox. For instance, querying the geonames api fails even though the preflight returns a 200. You can try it simply by replacing the url in your plnkr to use any of geonames api. The same request works fine on chrome.

sgarbesi commented 9 years ago

@kawazoe As a personal solution, I simply excluded the library unless the browser <= IE9

gscottolson commented 9 years ago

Thanks for the awesome work on xdomain/xhook, @jpillora.

We are seeing this preflighting issue, too. In our case, we xdomain/xhook is forcing preflighting for the two calls to api.segment.io. When removing xdomain from the page, the calls complete as simple POSTs.

cc @aseemk @tarajane @gasi

jpillora commented 9 years ago

Finally found the time to track down this bug, adding a upload progress listener xhr.upload.onload = function() {}; always causes an OPTIONS for some reason... So to fix it, I'll just proxy those events which have listeners. Fix should land soon