Totodore / socketioxide

A socket.io server implementation in Rust that integrates with the Tower ecosystem and the Tokio stack.
https://docs.rs/socketioxide
MIT License
1.13k stars 49 forks source link

Support for Sec-Websocket-Protocol #341

Closed spoorn closed 1 week ago

spoorn commented 1 week ago

Is your feature request related to a problem? Please describe.

Support Sec-Websocket-Protocol header in websocket handshake so the server can define subprotocols it accepts. Some info on the header field

Describe the solution you'd like

I'm not sure if it's expected to support this outside of socketioxide/engineioxide, such as directly via axum, but it seems socketioxide does the websocket upgrade in ws.rs and the response to the client should contain the subprotocol accepted by the server. SEC_WEBSOCKET_ACCEPT is already there.

I would imagine a user would have some way to configure for the websocket server connections (e.g. subprotocols to support) when creating the SocketIO layer

Totodore commented 1 week ago

We could set the Sec-Websocket-Protocol and it could improve the compatbility with other engine.io clients. But it would be set to "engine.io" as it is the only sub protocol used with websocket. There is no way that the user would be able to manually set it because it would not respect the ws protocol spec.

If you want to support subprotocols over socket.io you can use the auth payload or query params.