Skip to content

Commit c099338

Browse files
refactor: remove binary handling for the polling transport
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
1 parent fe093ba commit c099338

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Diff for: lib/transports/polling.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,10 @@ class Polling extends Transport {
109109
return;
110110
}
111111

112-
const isBinary = "application/octet-stream" === req.headers["content-type"];
113-
114112
this.dataReq = req;
115113
this.dataRes = res;
116114

117-
let chunks = isBinary ? Buffer.concat([]) : "";
115+
let chunks = "";
118116
const self = this;
119117

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

132130
function onData(data) {
133131
let contentLength;
134-
if (isBinary) {
135-
chunks = Buffer.concat([chunks, data]);
136-
contentLength = chunks.length;
137-
} else {
138-
chunks += data;
139-
contentLength = Buffer.byteLength(chunks);
140-
}
132+
chunks += data;
133+
contentLength = Buffer.byteLength(chunks);
141134

142135
if (contentLength > self.maxHttpBufferSize) {
143-
chunks = isBinary ? Buffer.concat([]) : "";
136+
chunks = "";
144137
req.connection.destroy();
145138
}
146139
}
@@ -161,7 +154,7 @@ class Polling extends Transport {
161154
}
162155

163156
req.on("close", onClose);
164-
if (!isBinary) req.setEncoding("utf8");
157+
req.setEncoding("utf8");
165158
req.on("data", onData);
166159
req.on("end", onEnd);
167160
}

0 commit comments

Comments
 (0)