Skip to content

Commit a8dd750

Browse files
authored
fix(engineio/ws): extra byte in websocket binary frame on EIO v3 (#278)
In v3 of the engine.io protocol, the packet type byte is prepended to the binary data that is sent out on a websocket binary frame. This byte needs to be stripped off the data before it's sent to the handler. Closes #277.
1 parent c8bbd22 commit a8dd750

File tree

1 file changed

+10
-2
lines changed
  • engineioxide/src/transport

1 file changed

+10
-2
lines changed

engineioxide/src/transport/ws.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ where
182182
}
183183
p => return Err(Error::BadPacket(p)),
184184
},
185-
Message::Binary(data) => {
185+
Message::Binary(mut data) => {
186+
if socket.protocol == ProtocolVersion::V3 && !data.is_empty() {
187+
// The first byte is the message type, which we don't need.
188+
let _ = data.remove(0);
189+
}
186190
engine.handler.on_binary(data, socket.clone());
187191
Ok(())
188192
}
@@ -212,7 +216,11 @@ where
212216
macro_rules! map_fn {
213217
($item:ident) => {
214218
let res = match $item {
215-
Packet::Binary(bin) | Packet::BinaryV3(bin) => {
219+
Packet::Binary(mut bin) | Packet::BinaryV3(mut bin) => {
220+
if socket.protocol == ProtocolVersion::V3 {
221+
// v3 protocol requires packet type as the first byte
222+
bin.insert(0, 0x04);
223+
}
216224
tx.feed(Message::Binary(bin)).await
217225
}
218226
Packet::Close => {

0 commit comments

Comments
 (0)