diff --git a/lib/transports/polling-xhr.js b/lib/transports/polling-xhr.js index c6f409200..53f5fcd8d 100755 --- a/lib/transports/polling-xhr.js +++ b/lib/transports/polling-xhr.js @@ -220,10 +220,6 @@ Request.prototype.create = function () { xhr.setRequestHeader('Accept', '*/*'); } catch (e) {} - if (this.supportsBinary) { - xhr.responseType = 'arraybuffer'; - } - // ie6 check if ('withCredentials' in xhr) { xhr.withCredentials = true; @@ -245,8 +241,8 @@ Request.prototype.create = function () { if (xhr.readyState === 2) { try { var contentType = xhr.getResponseHeader('Content-Type'); - if (contentType !== 'application/octet-stream') { - xhr.responseType = 'text'; + if (self.supportsBinary && contentType === 'application/octet-stream') { + xhr.responseType = 'arraybuffer'; } } catch (e) {} } @@ -359,8 +355,6 @@ Request.prototype.onLoad = function () { } catch (e) {} if (contentType === 'application/octet-stream') { data = this.xhr.response || this.xhr.responseText; - } else if (this.xhr.responseType === 'arraybuffer') { - data = String.fromCharCode.apply(null, new Uint8Array(this.xhr.response)); } else { data = this.xhr.responseText; } diff --git a/test/connection.js b/test/connection.js index 128224c4d..5b4d5a5d1 100644 --- a/test/connection.js +++ b/test/connection.js @@ -62,10 +62,28 @@ describe('connection', function () { if (global.Worker) { it('should work in a worker', function (done) { var worker = new Worker('/test/support/worker.js'); + var msg = 0; + var utf8yay = 'пойду сать всем мпокойной ночи'; worker.onmessage = function (e) { - expect(e.data); - done(); + msg++; + if (msg === 1) { + expect(e.data).to.be('hi'); + } else if (msg < 11) { + expect(e.data).to.be(utf8yay); + } else if (msg < 20) { + testBinary(e.data); + } else { + testBinary(e.data); + done(); + } }; + + function testBinary (data) { + var byteArray = new Uint8Array(data); + for (var i = 0; i < byteArray.byteLength; i++) { + expect(byteArray[i]).to.be(i); + } + } }); } diff --git a/test/support/public/worker.js b/test/support/public/worker.js index c11e57b04..4a46b570f 100644 --- a/test/support/public/worker.js +++ b/test/support/public/worker.js @@ -3,6 +3,14 @@ importScripts('/test/support/engine.io.js'); var socket = new eio.Socket(); + +var count = 0; socket.on('message', function (msg) { + count++; + if (count < 10) { + socket.send('give utf8'); + } else if (count < 20) { + socket.send('give binary'); + } postMessage(msg); }); diff --git a/test/support/server.js b/test/support/server.js index 06ba29800..ef9b45f9f 100644 --- a/test/support/server.js +++ b/test/support/server.js @@ -32,6 +32,9 @@ server.on('connection', function (socket) { } socket.send(abv); return; + } else if (data === 'give utf8') { + socket.send('пойду сать всем мпокойной ночи'); + return; } socket.send(data);