Repository navigation
Conversation
sendErrorResponse wrote the status line and the Server header but not the empty line that ends the header section, so every rejected handshake produced an incomplete HTTP response that a client could only end by waiting for the connection to close. A client asking for a WebSocket version other than 13 got 400 without a Sec-WebSocket-Version header, which RFC 6455 (section 4.2.2) requires so the client knows which version to use. Error responses now end with an empty line, and an unsupported version is answered with 426 and Sec-WebSocket-Version: 13.
This branch has not been deployed
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.
When the server rejects a WebSocket handshake,
WebSocketHandshake::sendErrorResponsewrites the status line and theServerheader, but not the empty line that ends the header section. For example, a request withoutSec-WebSocket-Keygets exactly these bytes before the connection closes:That's an incomplete HTTP response. A client can only treat it as finished once the connection drops, and strict HTTP clients report it as truncated.
Also, a client asking for a WebSocket version other than 13 gets a 400 without a
Sec-WebSocket-Versionheader. RFC 6455 section 4.2.2 says that in this case the server sends an appropriate error code (such as 426 Upgrade Required) and aSec-WebSocket-Versionheader with the versions it understands, so the client can retry with one of them (section 4.4).This change:
sendErrorResponseend the header section, and adds an optionalextraHeadersargument;Sec-WebSocket-Versionwith 426 andSec-WebSocket-Version: 13. The reason text and theWebSocketInitResulterror message are unchanged.The new section in
test/IXWebSocketServerTest.cppsendsSec-WebSocket-Version: 8. It expects a 426, theSec-WebSocket-Version: 13header, and the empty line that ends the headers. Without the change it fails (400 == 426). All 22 ctest tests pass with the change (Linux,USE_TLS=0), andgit clang-formatreports nothing for the change.