Skip to content

Honor client preference order in WebSocket sub-protocol negotiation - #10293

Merged
glen-84 merged 1 commit into
mainfrom
gai/websocket-subprotocol-client-preference
Aug 26, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/websocket-subprotocol-client-preference

Conversation

@glen-84

@glen-84 glen-84 commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

  • WebSocketConnection.TryAcceptConnection walks the client's Sec-WebSocket-Protocol list in the order it was sent and accepts the first sub-protocol that has a registered handler, so a client offering graphql-transport-ws, graphql-ws is answered with graphql-transport-ws. Handler registration and the ProtocolError close for unsupported protocols are unchanged.
  • The HTTP transport docs describe preference-ordered negotiation and the 1002 close.

Test plan

  • New WebSocketConnectionTests cover both preference orders, an unsupported protocol listed ahead of a supported one, each protocol offered alone, and unsupported-only offers closing with ProtocolError.
  • HotChocolate.AspNetCore.Tests and HotChocolate.Transport.Sockets.Client.Tests pass on net10.0.

Copilot AI lite review requested due to automatic review settings August 25, 2026 09:55
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Aug 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.TryAcceptConnection to iterate requested sub-protocols in client-specified order and accept the first supported one.
  • Add new WebSocketConnectionTests covering preference ordering and unsupported-protocol close behavior.
  • Update the HTTP transport documentation to describe preference-ordered negotiation and the 1002 close.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (15/15)

File Covered Changed Patch %
…/src/AspNetCore.Pipeline/Subscriptions/WebSocketConnection.cs 15 15 100.0% 🟢

Project coverage: 56.3% (265086/470693 lines)

@glen-84
glen-84 merged commit d2eb714 into main Aug 26, 2026
152 checks passed
@glen-84
glen-84 deleted the gai/websocket-subprotocol-client-preference branch August 26, 2026 08:14
This was referenced Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants