[Pkg-javascript-commits] [sockjs-client] 71/350: Fix #80 relax XHR requirements when same origin
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.
commit 30d303d239fddd1331f64613fa17809dfaf1ee18
Author: Bryce Kahle <bkahle at gmail.com>
Date: Fri Jun 6 18:19:43 2014 -0400
Fix #80 relax XHR requirements when same origin
---
lib/sockjs.js | 4 +++-
lib/trans-xhr-polling.js | 8 ++++++--
lib/trans-xhr-streaming.js | 18 +++++++-----------
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/lib/sockjs.js b/lib/sockjs.js
index a4c21b7..58fbaf9 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -209,6 +209,8 @@ SockJS.prototype._try_next_protocol = function(close_event) {
that._try_next_protocol();
}
+ var isSameOrigin = utils.isSameOriginUrl(that._base_url);
+
while(1) {
var protocol = that.protocol = that._protocols.shift();
if (!protocol) {
@@ -228,7 +230,7 @@ SockJS.prototype._try_next_protocol = function(close_event) {
}
if (!SockJS[protocol] ||
- !SockJS[protocol].enabled(that._options)) {
+ !SockJS[protocol].enabled(that._options, isSameOrigin)) {
that._debug('Skipping transport:', protocol);
} else {
var roundTrips = SockJS[protocol].roundTrips || 1;
diff --git a/lib/trans-xhr-polling.js b/lib/trans-xhr-polling.js
index 63d2ad9..506eb09 100644
--- a/lib/trans-xhr-polling.js
+++ b/lib/trans-xhr-polling.js
@@ -8,9 +8,9 @@
*/
var AjaxBasedTransport = require('./ajax-based');
-var XhrStreamingTransport = require('./trans-xhr-streaming');
var XhrReceiver = require('./trans-receiver-xhr');
var XHRCorsObject = require('./xhr-cors');
+var utils = require('./utils');
function XhrPollingTransport(ri, trans_url) {
this.run(ri, trans_url, '/xhr', XhrReceiver, XHRCorsObject);
@@ -18,7 +18,11 @@ function XhrPollingTransport(ri, trans_url) {
XhrPollingTransport.prototype = new AjaxBasedTransport();
-XhrPollingTransport.enabled = XhrStreamingTransport.enabled;
+XhrPollingTransport.enabled = function(options, isSameOrigin) {
+ if (window.XMLHttpRequest && isSameOrigin) return true;
+ return utils.isXHRCorsCapable() === 1;
+};
+
XhrPollingTransport.roundTrips = 2; // preflight, ajax
module.exports = XhrPollingTransport;
\ No newline at end of file
diff --git a/lib/trans-xhr-streaming.js b/lib/trans-xhr-streaming.js
index 4513761..ad6cfc0 100644
--- a/lib/trans-xhr-streaming.js
+++ b/lib/trans-xhr-streaming.js
@@ -10,6 +10,7 @@
var AjaxBasedTransport = require('./ajax-based');
var XhrReceiver = require('./trans-receiver-xhr');
var XHRCorsObject = require('./xhr-cors');
+var utils = require('./utils');
function XhrStreamingTransport(ri, trans_url) {
this.run(ri, trans_url, '/xhr_streaming', XhrReceiver, XHRCorsObject);
@@ -17,17 +18,12 @@ function XhrStreamingTransport(ri, trans_url) {
XhrStreamingTransport.prototype = new AjaxBasedTransport();
-XhrStreamingTransport.enabled = function() {
- // Support for CORS Ajax aka Ajax2? Opera 12 claims CORS but
- // doesn't do streaming.
- try {
- return (window.XMLHttpRequest &&
- 'withCredentials' in new XMLHttpRequest() &&
- (!/opera/i.test(navigator.userAgent)));
- }
- catch (ignored) {
- return false;
- }
+XhrStreamingTransport.enabled = function(options, isSameOrigin) {
+ // Opera doesn't support xhr-streaming
+ if (/opera/i.test(navigator.userAgent)) return false;
+ if (window.XMLHttpRequest && isSameOrigin) return true;
+
+ return utils.isXHRCorsCapable() === 1;
};
XhrStreamingTransport.roundTrips = 2; // preflight, ajax
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git
More information about the Pkg-javascript-commits
mailing list