Repository navigation
Honor client preference order in WebSocket sub-protocol negotiation - #10293
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Hot Chocolate’s WebSocket sub-protocol negotiation to honor the client’s Sec-WebSocket-Protocol preference order, selecting the first client-offered protocol that has a registered handler. It also aligns the documentation and adds targeted tests to validate the negotiation behavior and the 1002 (ProtocolError) close for unsupported protocol offers.
Changes:
- Update
WebSocketConnection.TryAcceptConnectionto iterate requested sub-protocols in client-specified order and accept the first supported one. - Add new
WebSocketConnectionTestscovering preference ordering and unsupported-protocol close behavior. - Update the HTTP transport documentation to describe preference-ordered negotiation and the
1002close.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| website/content/docs/hotchocolate/server/http-transport.md | Documents preference-ordered Sec-WebSocket-Protocol negotiation and 1002 close behavior. |
| src/HotChocolate/AspNetCore/test/AspNetCore.Tests/Subscriptions/WebSocketConnectionTests.cs | Adds tests validating negotiation order and ProtocolError close when no offered protocols are supported. |
| src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Subscriptions/WebSocketConnection.cs | Implements client-preference-ordered protocol selection by scanning requested protocols first. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Patch coverage100.0% of changed lines covered (15/15)
Project coverage: 56.3% (265086/470693 lines) |
This was referenced Aug 29, 2026
Merged
This was referenced Sep 8, 2026
Closed
Closed
This was referenced Sep 15, 2026
Closed
[nuget][SUI_Matcher]- Bump the sui-package-updates group with 20 updates
DFE-Digital/SUI_Matcher#405
Closed
Closed
This was referenced Sep 22, 2026
Closed
Closed
[nuget][SUI_Matcher]- Bump the sui-package-updates group with 20 updates
DFE-Digital/SUI_Matcher#410
Merged
This was referenced Oct 5, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WebSocketConnection.TryAcceptConnectionwalks the client'sSec-WebSocket-Protocollist in the order it was sent and accepts the first sub-protocol that has a registered handler, so a client offeringgraphql-transport-ws, graphql-wsis answered withgraphql-transport-ws. Handler registration and theProtocolErrorclose for unsupported protocols are unchanged.1002close.Test plan
WebSocketConnectionTestscover both preference orders, an unsupported protocol listed ahead of a supported one, each protocol offered alone, and unsupported-only offers closing withProtocolError.HotChocolate.AspNetCore.TestsandHotChocolate.Transport.Sockets.Client.Testspass on net10.0.