You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

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