Skip to content

Commit

Permalink
refactor: remove binary handling for the polling transport
Browse files Browse the repository at this point in the history
Since Engine.IO v4, the binary payloads are always encoded as base64
with the polling transport.

See https://github.com/socketio/engine.io-protocol#difference-between-v3-and-v4
  • Loading branch information
darrachequesne committed Oct 21, 2020
1 parent fe093ba commit c099338
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/transports/polling.js
Expand Up @@ -109,12 +109,10 @@ class Polling extends Transport {
return;
}

const isBinary = "application/octet-stream" === req.headers["content-type"];

this.dataReq = req;
this.dataRes = res;

let chunks = isBinary ? Buffer.concat([]) : "";
let chunks = "";
const self = this;

function cleanup() {
Expand All @@ -131,16 +129,11 @@ class Polling extends Transport {

function onData(data) {
let contentLength;
if (isBinary) {
chunks = Buffer.concat([chunks, data]);
contentLength = chunks.length;
} else {
chunks += data;
contentLength = Buffer.byteLength(chunks);
}
chunks += data;
contentLength = Buffer.byteLength(chunks);

if (contentLength > self.maxHttpBufferSize) {
chunks = isBinary ? Buffer.concat([]) : "";
chunks = "";
req.connection.destroy();
}
}
Expand All @@ -161,7 +154,7 @@ class Polling extends Transport {
}

req.on("close", onClose);
if (!isBinary) req.setEncoding("utf8");
req.setEncoding("utf8");
req.on("data", onData);
req.on("end", onEnd);
}
Expand Down

0 comments on commit c099338

Please sign in to comment.