Skip to content

Commit

Permalink
refactor: remove binary handling for the polling transport (bis)
Browse files Browse the repository at this point in the history
The `supportsBinary` attribute and the `forceBase64` option are kept
untouched, though they are not used by the polling transport, which
now always converts the payloads to base64.

Related: socketio/socket.io-client#1391
  • Loading branch information
darrachequesne committed Nov 17, 2020
1 parent 177b95f commit 89cb771
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
34 changes: 4 additions & 30 deletions lib/transports/polling-xhr.js
Expand Up @@ -59,11 +59,7 @@ class XHR extends Polling {
* @api private
*/
request(opts = {}) {
Object.assign(
opts,
{ supportsBinary: this.supportsBinary, xd: this.xd, xs: this.xs },
this.opts
);
Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
return new Request(this.uri(), opts);
}

Expand All @@ -75,11 +71,9 @@ class XHR extends Polling {
* @api private
*/
doWrite(data, fn) {
const isBinary = typeof data !== "string" && data !== undefined;
const req = this.request({
method: "POST",
data: data,
isBinary: isBinary
data: data
});
const self = this;
req.on("success", fn);
Expand Down Expand Up @@ -122,8 +116,6 @@ class Request extends Emitter {
this.uri = uri;
this.async = false !== opts.async;
this.data = undefined !== opts.data ? opts.data : null;
this.isBinary = opts.isBinary;
this.supportsBinary = opts.supportsBinary;

this.create();
}
Expand Down Expand Up @@ -164,17 +156,11 @@ class Request extends Emitter {
}
}
}
} catch (e) {
console.log(e);
}
} catch (e) {}

if ("POST" === this.method) {
try {
if (this.isBinary) {
xhr.setRequestHeader("Content-type", "application/octet-stream");
} else {
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
}
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
} catch (e) {}
}

Expand All @@ -200,18 +186,6 @@ class Request extends Emitter {
};
} else {
xhr.onreadystatechange = function() {
if (xhr.readyState === 2) {
try {
const contentType = xhr.getResponseHeader("Content-Type");
if (
(self.supportsBinary &&
contentType === "application/octet-stream") ||
contentType === "application/octet-stream; charset=UTF-8"
) {
xhr.responseType = "arraybuffer";
}
} catch (e) {}
}
if (4 !== xhr.readyState) return;
if (200 === xhr.status || 1223 === xhr.status) {
self.onLoad();
Expand Down
7 changes: 1 addition & 6 deletions lib/transports/websocket.js
Expand Up @@ -27,12 +27,7 @@ class WS extends Transport {
constructor(opts) {
super(opts);

const forceBase64 = opts && opts.forceBase64;
if (forceBase64) {
this.supportsBinary = false;
}
// WebSockets support binary
this.supportsBinary = true;
this.supportsBinary = !opts.forceBase64;
}

/**
Expand Down

0 comments on commit 89cb771

Please sign in to comment.