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

Properly respond with sec-websocket-protocol under http/2 #3141

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

coolreader18
Copy link

@coolreader18 coolreader18 commented Jan 3, 2025

Motivation

Was looking at the ws code and noticed that the subprotocol never gets properly communicated to the client if the connection is HTTP/2.

Solution

Add the sec-websocket-protocol header irrespective of HTTP version. A response with that header is still a valid HTTP/2 websocket handshake, as per RFC8441.

@jplatte
Copy link
Member

jplatte commented Jan 3, 2025

cc @SabrinaJewson

@SabrinaJewson
Copy link
Contributor

Ah, looks good! Can you modify the http2 test to check for this as well? (Or write a new test)

mut socket: WebSocketStream<S>,
headers: &http::HeaderMap,
) {
dbg!(headers);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is complaining about this line. dbg! should only be used locally when debugging some issues.
Can you remove this line?

Suggested change
dbg!(headers);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh whoops lol, yep.

@coolreader18 coolreader18 force-pushed the http2-websocket-subprotocol branch from 9a4f267 to 95f2535 Compare January 6, 2025 16:01
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.

4 participants