[Pkg-javascript-commits] [sockjs-client] 159/350: Add debug to browser xhr. Fix IE6 bad url/port cases.
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:58 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 c02b276d9c8a1ec8b1f1fd4641edacc90e1ed12c
Author: Bryce Kahle <bkahle at gmail.com>
Date: Thu Oct 16 21:06:06 2014 -0400
Add debug to browser xhr. Fix IE6 bad url/port cases.
---
lib/transport/browser/abstract-xhr.js | 35 +++++++++++++++++++++++++++++++++--
tests/lib/senders.js | 8 +++++---
2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/lib/transport/browser/abstract-xhr.js b/lib/transport/browser/abstract-xhr.js
index 9091c6c..eda938e 100644
--- a/lib/transport/browser/abstract-xhr.js
+++ b/lib/transport/browser/abstract-xhr.js
@@ -3,9 +3,11 @@
var EventEmitter = require('events').EventEmitter
, util = require('util')
, utils = require('../../utils/event')
+ , debug = require('debug')('sockjs-client:browser:xhr')
;
function AbstractXHRObject(method, url, payload, opts) {
+ debug(method, url);
var self = this;
EventEmitter.call(this);
@@ -18,7 +20,15 @@ function AbstractXHRObject(method, url, payload, opts) {
this.xhr = new global.ActiveXObject('Microsoft.XMLHTTP');
} catch(x) {}
}
+ if (!this.xhr) {
+ debug('no xhr');
+ this.emit('finish', 0, 'no xhr support');
+ this._cleanup();
+ return;
+ }
+
if (global.ActiveXObject || global.XDomainRequest) {
+ debug('adding to url to prevent POST cache');
// IE8 caches even POSTs
url += ((url.indexOf('?') === -1) ? '?' : '&') + 't=' + Date.now();
}
@@ -26,11 +36,13 @@ function AbstractXHRObject(method, url, payload, opts) {
// Explorer tends to keep connection open, even after the
// tab gets closed: http://bugs.jquery.com/ticket/5280
this.unloadRef = utils.unloadAdd(function(){
+ debug('unload cleanup');
self._cleanup(true);
});
try {
this.xhr.open(method, url, true);
} catch(e) {
+ debug('exception', e);
// IE raises an exception on wrong port.
this.emit('finish', 0, '');
this._cleanup();
@@ -38,6 +50,7 @@ function AbstractXHRObject(method, url, payload, opts) {
}
if (!opts || !opts.noCredentials) {
+ debug('withCredentials');
// Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
// "This never affects same-site requests."
this.xhr.withCredentials = 'true';
@@ -52,6 +65,7 @@ function AbstractXHRObject(method, url, payload, opts) {
if (self.xhr) {
var x = self.xhr;
var text, status;
+ debug('readyState', x.readyState);
switch (x.readyState) {
case 3:
// IE doesn't like peeking into responseText or status
@@ -60,6 +74,7 @@ function AbstractXHRObject(method, url, payload, opts) {
status = x.status;
text = x.responseText;
} catch (e) {}
+ debug('status', status);
// IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
if (status === 1223) {
status = 204;
@@ -67,31 +82,47 @@ function AbstractXHRObject(method, url, payload, opts) {
// IE does return readystate == 3 for 404 answers.
if (text && text.length > 0) {
+ debug('chunk');
self.emit('chunk', status, text);
}
break;
case 4:
status = x.status;
+ debug('status', status);
// IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
if (status === 1223) {
status = 204;
}
+ // IE6 returns this for a bad port
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/aa383770(v=vs.85).aspx
+ if (status === 12005) {
+ status = 0;
+ }
+ debug('finish', status, x.responseText);
self.emit('finish', status, x.responseText);
self._cleanup(false);
break;
}
}
};
- self.xhr.send(payload);
+
+ try {
+ self.xhr.send(payload);
+ } catch (e) {
+ self.emit('finish', 0, '');
+ self._cleanup(false);
+ }
}
util.inherits(AbstractXHRObject, EventEmitter);
AbstractXHRObject.prototype._cleanup = function(abort) {
+ debug('cleanup');
if (!this.xhr) {
return;
}
+ this.removeAllListeners();
utils.unloadDel(this.unloadRef);
// IE needs this field to be a function
@@ -106,7 +137,7 @@ AbstractXHRObject.prototype._cleanup = function(abort) {
};
AbstractXHRObject.prototype.close = function() {
- this.removeAllListeners();
+ debug('close');
this._cleanup(true);
};
diff --git a/tests/lib/senders.js b/tests/lib/senders.js
index 952862d..deb2e30 100644
--- a/tests/lib/senders.js
+++ b/tests/lib/senders.js
@@ -35,7 +35,8 @@ function ajaxStreaming (Obj) {
function wrongUrl(Obj, url, statuses) {
it('wrong url ' + url, function (done) {
- this.timeout(10000);
+ // Selenium has a long timeout for when it can't connect to the port
+ this.timeout(20000);
var x = new Obj('GET', url, null);
x.on('chunk', function () {
expect().fail('No chunk should be received');
@@ -58,7 +59,8 @@ function wrongPort (Obj) {
var ports = [25, 8999, 65300];
ports.forEach(function (port) {
- wrongUrl(Obj, badUrl + port + '/wrong_url_indeed.txt', [0]);
+ // Sauce Labs/Selenium returns 400 when it can't connect to the port
+ wrongUrl(Obj, badUrl + port + '/wrong_url_indeed.txt', [0, 400]);
});
}
@@ -78,6 +80,6 @@ describe('Senders', function () {
ajaxSimple(Xdr);
ajaxStreaming(Xdr);
wrongPort(Xdr);
- wrongUrl(Xdr, testUtils.getOriginUrl() + '/wrong_url_indeed.txt', [0]);
+ wrongUrl(Xdr, testUtils.getOriginUrl() + '/wrong_url_indeed.txt', [0, 400]);
});
});
--
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