Skip to content

Conversation

coolreader18
Copy link
Contributor

Motivation

This allows you to check the subprotocol before spawning the websocket task, letting you e.g. bail out with a 4XX if no subprotocol was provided.

Solution

Add a WebSocketUpgrade::selected_protocol(&self) -> Option<&HeaderValue> function, so you can access the same value as WebSocket::protocol() without yet calling on_upgrade.

@coolreader18
Copy link
Contributor Author

Is there anyone who could take a look at this?

@coolreader18 coolreader18 force-pushed the websocketupgrade-selected-protocol branch from be17d61 to dd7ff00 Compare April 11, 2025 21:40
@jplatte
Copy link
Member

jplatte commented Apr 24, 2025

Ping @SabrinaJewson, as the resident WebSockets and SSE expert ^^

@SabrinaJewson
Copy link
Contributor

Yeah, this looks good to me. We already expose the functionality, so this is just exposing it a little earlier.

@jplatte jplatte merged commit 58f63bb into tokio-rs:main Apr 24, 2025
18 checks passed
@coolreader18 coolreader18 deleted the websocketupgrade-selected-protocol branch May 7, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants