Skip to content

Commit

Permalink
Fallback to jsonp-polling in IE when going cross scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1mmy committed Jul 12, 2012
1 parent cd3ca61 commit 26136a2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion packages/stream/sockjs-0.3.1.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// XXX METEOR changes in <METEOR>

/* SockJS client, version 0.3.1, http://sockjs.org, MIT License
Copyright (c) 2011-2012 VMware, Inc.
Expand Down Expand Up @@ -202,6 +204,17 @@ utils.isSameOriginUrl = function(url_a, url_b) {
url_b.split('/').slice(0,3).join('/'));
};

// <METEOR>
utils.isSameOriginScheme = function(url_a, url_b) {
if (!url_b) url_b = _window.location.href;

return (url_a.split(':')[0]
===
url_b.split(':')[0]);
};
// </METEOR>


utils.getParentDomain = function(url) {
// ipv4 ip address
if (/^[0-9.]*$/.test(url)) return url;
Expand Down Expand Up @@ -1148,6 +1161,14 @@ SockJS.prototype._applyInfo = function(info, rtt, protocols_whitelist) {
that._options.info.null_origin = !_document.domain;
var probed = utils.probeProtocols();
that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
// <METEOR>
// Hack to avoid XDR when using different protocols
// We're on IE trying to do cross-protocol. jsonp only.
if (!utils.isSameOriginScheme(that._base_url) &&
2 === utils.isXHRCorsCapable()) {
that._protocols = ['jsonp-polling'];
}
// </METEOR>
};
// [*] End of lib/sockjs.js

Expand Down Expand Up @@ -1945,7 +1966,14 @@ var createInfoReceiver = function(base_url) {
case 1:
return new InfoReceiver(base_url, utils.XHRCorsObject);
case 2:
return new InfoReceiver(base_url, utils.XDRObject);
// <METEOR>
// XDR doesn't work across different schemes
// http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
if (utils.isSameOriginScheme(base_url))
return new InfoReceiver(base_url, utils.XDRObject);
else
return new InfoReceiverFake();
// </METEOR>
case 3:
// Opera
return new InfoReceiverIframe(base_url);
Expand Down

0 comments on commit 26136a2

Please sign in to comment.