Repository navigation
Send no Sec-WebSocket-Protocol header for the JSON transport - #69
Merged
FZambia merged 1 commit intoOct 13, 2026
Merged
Conversation
For JSON the client passed subprotocols=[] to websockets.connect(), which then sends the header with an empty value. RFC 6455 allows the header only with at least one subprotocol, and servers such as the websockets one reject the handshake. Passing None leaves the header out. The fake test server no longer needs protobuf for this reason. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks @damirych ! |
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.
What changed
For the JSON transport,
_create_connectionnow passessubprotocols=Nonetowebsockets.connect()instead of[]. The protobuf transport still offerscentrifuge-protobuf.Why
With
[], websockets sendsSec-WebSocket-Protocol:with an empty value. RFC 6455 defines the header as a non-empty list of tokens (1#token, section 4.1), and strict servers refuse the handshake. The websockets server is one of them, which is whytests/fake_server.pysays it speaks protobuf only because "the JSON client transport sends an emptySec-WebSocket-Protocolheader that thewebsocketsserver rejects". Centrifugo accepts the empty header, so this only shows up behind stricter servers or proxies.centrifuge-js leaves the subprotocol out for JSON too (
transport_websocket.ts):The paragraph in the
tests/fake_server.pydocstring that gave this as the reason for protobuf is reduced to "it speaks protobuf only".Verification
Added
tests/test_json_handshake.py, which needs no Docker. A plainwebsockets.serve()server answers the JSON connect command and records theSec-WebSocket-Protocolheaders of each handshake. The test asserts that a JSON client ends upCONNECTEDand sent no such header. Onmasterit fails: the handshake is refused and the client staysCONNECTING.Also ran:
tests/test_client.pyagainst this repo's docker-compose Centrifugo, which runs its tests over both JSON and protobuf: 62 tests OK.test_filter,test_fossil,test_proxy,test_ssl,test_state_invalidation,test_sub_refresh,test_background_tasks,test_ready,test_refresh,test_unsubscribe,test_utils) together with the new one: 62 tests OK.ruff check .andruff format --check: clean.🤖 Generated with Claude Code