Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 11 additions & 21 deletions lib/transports/polling-xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/transports/polling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down