[Pkg-javascript-commits] [sockjs-client] 116/434: Chunking test shall work on opera.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository sockjs-client.
commit 29ab08a2aba07700623cee636bc68a48a8d2fb6d
Author: Marek Majkowski <majek04 at gmail.com>
Date: Mon Sep 5 16:39:10 2011 +0100
Chunking test shall work on opera.
Although opera chunking handling in xhr is, quite bad - we can't do xhr-streaming, we can indeed use it for chunking detection. Opera limitation is that it runs onreadystate=3 event exactly once. This is enough for chunking detecion.
If we get readystate == 3, and the contents suggest that we haven't received full response - clearly chunking works.
---
lib/chunking-test.js | 36 +++++++++++++++++++-----------------
lib/trans-receiver-xhr.js | 5 ++---
lib/utils.js | 10 ----------
3 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/lib/chunking-test.js b/lib/chunking-test.js
index c6937bf..fd06a7e 100644
--- a/lib/chunking-test.js
+++ b/lib/chunking-test.js
@@ -1,20 +1,20 @@
var doChunkingTest = function(base_url, callback, cors) {
var recv = new XhrReceiver(base_url + '/chunking_test', {cors: cors});
- var chunk_nos = {};
+ var result = 0;
recv.onmessage = function(e) {
- chunk_nos[e.chunk_no] = true;
- // Now a cool hack: we can stop receiving after we got more
- // than one chunk:
- if (utils.objectLength(chunk_nos) > 1) {
+ // Now a cool hack: we can stop receiving after we got at least
+ // one chunk, contains some data, but not everyting.
+ var l = e.responsetext.split('h\n').length;
+ if(e.readystate === 3 && l > 0 && l < 6 ) {
+ result = l;
recv.abort();
}
};
recv.onclose = function(e) {
recv = recv.onmessage = recv.onclose = null;
- var l = utils.objectLength(chunk_nos);
- utils.log('Chunking test: ' + (l > 1 ? 'passed' : 'failed')
- + ' (' + l + ' chunks received)');
- callback(l > 1);
+ utils.log('Chunking test: ' + (result ? 'passed' : 'failed')
+ + ' (' + result + ' chunk received)');
+ callback(!!result);
};
};
@@ -26,7 +26,7 @@ var ChunkingTestIframe = FacadeJS['w-iframe-chunking-test'] = function (ri, tran
};
ChunkingTestIframe.prototype.doCleanup = function() {};
-var chunkingTestUncached = function(base_url, callback) {
+var chunkingTestUncached = SockJS.chunkingTest = function(base_url, callback) {
// 1. CORS
if (_window.XDomainRequest ||
(_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest())) {
@@ -37,16 +37,18 @@ var chunkingTestUncached = function(base_url, callback) {
if (IframeTransport.enabled()) {
var ifr = new IframeTransport();
ifr.protocol = 'w-iframe-chunking-test';
- var mock_ri = {
- _options: {},
- _didClose: function() {},
- _didMessage: function(r) {
- if(r.slice(0,1) === 'm') {
- callback(r.slice(1));
- }
+ var fun = function(r) {
+ if (ifr){
+ callback(r === 'mtrue');
ifr.doCleanup();
+ ifr = null;
}
};
+ var mock_ri = {
+ _options: {},
+ _didClose: fun,
+ _didMessage: fun
+ };
ifr.i_constructor(mock_ri, '', base_url);
return;
}
diff --git a/lib/trans-receiver-xhr.js b/lib/trans-receiver-xhr.js
index 14a3a94..c6428e0 100644
--- a/lib/trans-receiver-xhr.js
+++ b/lib/trans-receiver-xhr.js
@@ -2,10 +2,8 @@
var XhrReceiver = function(url, opts) {
var that = this;
var buf_pos = 0;
- var chunk_no = 0;
var orsc = function (xhr, e, abort_reason) {
if (xhr.readyState === 3 || xhr.readyState === 4) {
- chunk_no += 1;
// IE doesn't like peeking into responseText or status on
// XHR and readystate=3
try {
@@ -23,7 +21,8 @@ var XhrReceiver = function(url, opts) {
that.dispatchEvent(
new SimpleEvent('message', {
data: msg,
- chunk_no: chunk_no
+ readystate: xhr.readyState,
+ responsetext: responseText
}));
}
}
diff --git a/lib/utils.js b/lib/utils.js
index c5aa481..2b4b706 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -66,16 +66,6 @@ utils.objectExtend = function(dst, src) {
return dst;
};
-utils.objectLength = function(obj) {
- var i = 0;
- for(var k in obj) {
- if (obj.hasOwnProperty(k)) {
- i += 1;
- }
- }
- return i;
-};
-
// Try to clear some headers, in order to save bandwidth. For
// reference see:
// http://blog.mibbit.com/?p=143
--
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