xmlhttprequest.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // browser shim for xmlhttprequest module
  2. var hasCORS = require('has-cors');
  3. var globalThis = require('./globalThis');
  4. module.exports = function (opts) {
  5. var xdomain = opts.xdomain;
  6. // scheme must be same when usign XDomainRequest
  7. // http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
  8. var xscheme = opts.xscheme;
  9. // XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
  10. // https://github.com/Automattic/engine.io-client/pull/217
  11. var enablesXDR = opts.enablesXDR;
  12. // XMLHttpRequest can be disabled on IE
  13. try {
  14. if ('undefined' !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
  15. return new XMLHttpRequest();
  16. }
  17. } catch (e) { }
  18. // Use XDomainRequest for IE8 if enablesXDR is true
  19. // because loading bar keeps flashing when using jsonp-polling
  20. // https://github.com/yujiosaka/socke.io-ie8-loading-example
  21. try {
  22. if ('undefined' !== typeof XDomainRequest && !xscheme && enablesXDR) {
  23. return new XDomainRequest();
  24. }
  25. } catch (e) { }
  26. if (!xdomain) {
  27. try {
  28. return new globalThis[['Active'].concat('Object').join('X')]('Microsoft.XMLHTTP');
  29. } catch (e) { }
  30. }
  31. };