Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subprotocol support #17

Closed
ziad-floosi opened this issue Aug 7, 2022 · 6 comments
Closed

Subprotocol support #17

ziad-floosi opened this issue Aug 7, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@ziad-floosi
Copy link

ziad-floosi commented Aug 7, 2022

Are there any plans for subprotocol support in this library?

@miguelgrinberg
Copy link
Owner

I assume you are interested in support for selecting a subprotocol during handshake? That is doable, what I'm probably not going to add here is implementations for actual subprotocols.

@miguelgrinberg miguelgrinberg self-assigned this Aug 7, 2022
@miguelgrinberg miguelgrinberg added the enhancement New feature or request label Aug 7, 2022
@ziad-floosi
Copy link
Author

Yeah, just selecting a subprotocol. Chrome fails to connect if the handshake reply doesn't contain the subprotocols sent in the Sec-WebSocket-Protocol header.

@miguelgrinberg
Copy link
Owner

Okay, I'll look into it.

@miguelgrinberg miguelgrinberg transferred this issue from miguelgrinberg/flask-sock Aug 7, 2022
@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Aug 7, 2022

@ziad-floosi I think this should do it. To test, install simple-websocket directly from the main branch of this repository. When using Flask-Sock, you can pass the list of subprotocols accepted by the server in the SOCK_SERVER_OPTIONS dictionary (see https://flask-sock.readthedocs.io/en/latest/quickstart.html#configuration).

If the client requests a subprotocol or a list of them, the server will find the first subprotocol that it knows about and include it in the acceptance message. In the server, you can get the selected protocol inside the websocket route with ws.subprotocol.

@ziad-floosi
Copy link
Author

Works perfectly, thank you so much for the quick fix. There seems to be some log message that prints out the subprotocol list when the WS server receives a request. Not super important, but just wanted to let you know.

https://github.com/miguelgrinberg/simple-websocket/blob/main/src/simple_websocket/ws.py#L339-L340

@miguelgrinberg
Copy link
Owner

miguelgrinberg commented Aug 8, 2022

Released as simple-websocket 0.8.0. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants