fix(bun): report the requested subprotocol on WSContext.protocol#5059
Open
greymoth-jp wants to merge 1 commit into
Open
fix(bun): report the requested subprotocol on WSContext.protocol#5059greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
The Bun adapter put the request URL in WSContext.protocol. Read the first value of the Sec-WebSocket-Protocol header instead, so it reports the subprotocol like the deno and cloudflare adapters do.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5059 +/- ##
==========================================
+ Coverage 79.09% 79.11% +0.02%
==========================================
Files 154 154
Lines 10727 10726 -1
Branches 2238 2239 +1
==========================================
+ Hits 8484 8486 +2
+ Misses 2243 2240 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
yusukebe
reviewed
Jun 30, 2026
Member
There was a problem hiding this comment.
Can you add a test to test that the value of ws.protocol will be '' if you do not set the sec-websocket-protocol header?
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.
The Bun WebSocket adapter sets
WSContext.protocolto the request URL:WSContext.protocolis supposed to mirror the standardWebSocket.protocolproperty (the connection's subprotocol), so on Bun it currently returns something likehttp://localhost/wsinstead of the subprotocol. The deno and cloudflare adapters read it from the platform socket (socket.protocolandserver.protocol), so this is a Bun-only inconsistency.This reads the first value of the
Sec-WebSocket-Protocolheader, the same way the deno adapter does (#4955), and stores it on the data that backsWSContext.protocol.Added a test that upgrades with
Sec-WebSocket-Protocol: chat, superchatand assertswsContext.protocolischat. Without this change it fails withexpected 'http://localhost/ws' to be 'chat'.