diff --git a/lib/transports/polling-xhr.js b/lib/transports/polling-xhr.js index dbf000f43..297bac59e 100755 --- a/lib/transports/polling-xhr.js +++ b/lib/transports/polling-xhr.js @@ -205,11 +205,6 @@ Request.prototype.create = function () { } } } catch (e) {} - if (this.supportsBinary) { - // This has to be done after open because Firefox is stupid - // http://stackoverflow.com/questions/13216903/get-binary-data-with-xmlhttprequest-in-a-firefox-extension - xhr.responseType = 'arraybuffer'; - } if ('POST' === this.method) { try { @@ -243,6 +238,15 @@ Request.prototype.create = function () { }; } else { xhr.onreadystatechange = function () { + if (xhr.readyState === 2) { + var contentType; + try { + contentType = xhr.getResponseHeader('Content-Type'); + } catch (e) {} + if (contentType === 'application/octet-stream') { + xhr.responseType = 'arraybuffer'; + } + } if (4 !== xhr.readyState) return; if (200 === xhr.status || 1223 === xhr.status) { self.onLoad(); @@ -348,26 +352,12 @@ Request.prototype.onLoad = function () { try { var contentType; try { - contentType = this.xhr.getResponseHeader('Content-Type').split(';')[0]; + contentType = this.xhr.getResponseHeader('Content-Type'); } catch (e) {} if (contentType === 'application/octet-stream') { data = this.xhr.response || this.xhr.responseText; } else { - if (!this.supportsBinary) { - data = this.xhr.responseText; - } else { - try { - data = String.fromCharCode.apply(null, new Uint8Array(this.xhr.response)); - } catch (e) { - var ui8Arr = new Uint8Array(this.xhr.response); - var dataArray = []; - for (var idx = 0, length = ui8Arr.length; idx < length; idx++) { - dataArray.push(ui8Arr[idx]); - } - - data = String.fromCharCode.apply(null, dataArray); - } - } + data = this.xhr.responseText; } } catch (e) { this.onError(e); diff --git a/lib/transports/polling.js b/lib/transports/polling.js index e600af601..22e0ed0e7 100644 --- a/lib/transports/polling.js +++ b/lib/transports/polling.js @@ -145,7 +145,7 @@ Polling.prototype.onData = function (data) { }; // decode payload - parser.decodePayload(data, this.socket.binaryType, this.supportsBinary, callback); + parser.decodePayload(data, this.socket.binaryType, false, callback); // if an event did not trigger closing if ('closed' !== this.readyState) {