Skip to content

Commit 89cb771

Browse files
refactor: remove binary handling for the polling transport (bis)
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
1 parent 177b95f commit 89cb771

File tree

2 files changed

+5
-36
lines changed

2 files changed

+5
-36
lines changed

lib/transports/polling-xhr.js

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ class XHR extends Polling {
5959
* @api private
6060
*/
6161
request(opts = {}) {
62-
Object.assign(
63-
opts,
64-
{ supportsBinary: this.supportsBinary, xd: this.xd, xs: this.xs },
65-
this.opts
66-
);
62+
Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);
6763
return new Request(this.uri(), opts);
6864
}
6965

@@ -75,11 +71,9 @@ class XHR extends Polling {
7571
* @api private
7672
*/
7773
doWrite(data, fn) {
78-
const isBinary = typeof data !== "string" && data !== undefined;
7974
const req = this.request({
8075
method: "POST",
81-
data: data,
82-
isBinary: isBinary
76+
data: data
8377
});
8478
const self = this;
8579
req.on("success", fn);
@@ -122,8 +116,6 @@ class Request extends Emitter {
122116
this.uri = uri;
123117
this.async = false !== opts.async;
124118
this.data = undefined !== opts.data ? opts.data : null;
125-
this.isBinary = opts.isBinary;
126-
this.supportsBinary = opts.supportsBinary;
127119

128120
this.create();
129121
}
@@ -164,17 +156,11 @@ class Request extends Emitter {
164156
}
165157
}
166158
}
167-
} catch (e) {
168-
console.log(e);
169-
}
159+
} catch (e) {}
170160

171161
if ("POST" === this.method) {
172162
try {
173-
if (this.isBinary) {
174-
xhr.setRequestHeader("Content-type", "application/octet-stream");
175-
} else {
176-
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
177-
}
163+
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
178164
} catch (e) {}
179165
}
180166

@@ -200,18 +186,6 @@ class Request extends Emitter {
200186
};
201187
} else {
202188
xhr.onreadystatechange = function() {
203-
if (xhr.readyState === 2) {
204-
try {
205-
const contentType = xhr.getResponseHeader("Content-Type");
206-
if (
207-
(self.supportsBinary &&
208-
contentType === "application/octet-stream") ||
209-
contentType === "application/octet-stream; charset=UTF-8"
210-
) {
211-
xhr.responseType = "arraybuffer";
212-
}
213-
} catch (e) {}
214-
}
215189
if (4 !== xhr.readyState) return;
216190
if (200 === xhr.status || 1223 === xhr.status) {
217191
self.onLoad();

lib/transports/websocket.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ class WS extends Transport {
2727
constructor(opts) {
2828
super(opts);
2929

30-
const forceBase64 = opts && opts.forceBase64;
31-
if (forceBase64) {
32-
this.supportsBinary = false;
33-
}
34-
// WebSockets support binary
35-
this.supportsBinary = true;
30+
this.supportsBinary = !opts.forceBase64;
3631
}
3732

3833
/**

0 commit comments

Comments
 (0)