Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a518cfe

Browse files
committedMar 1, 2024·
Fix extra byte in websocket binary frame on EIO v3
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 a518cfe

File tree

1 file changed

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

1 file changed

+11
-2
lines changed
 

‎engineioxide/src/transport/ws.rs

+11-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,12 @@ where
212216
macro_rules! map_fn {
213217
($item:ident) => {
214218
let res = match $item {
215-
Packet::Binary(bin) | Packet::BinaryV3(bin) => {
219+
Packet::Binary(bin) => {
220+
tx.feed(Message::Binary(bin)).await
221+
}
222+
Packet::BinaryV3(mut bin) => {
223+
// v3 protocol requires packet type as the first byte
224+
bin.insert(0, 0x04);
216225
tx.feed(Message::Binary(bin)).await
217226
}
218227
Packet::Close => {

0 commit comments

Comments
 (0)
Please sign in to comment.