Repository navigation
Conversation
If the `verifyClient` callback rejects a client with a status code that is not in `http.STATUS_CODES`, `abortHandshake()` throws a `TypeError` and leaves the socket open, or writes `undefined` as the reason phrase if a message is provided. Fall back to `Unknown` instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
What is the use case? I mean, what is the status code not in |
Member
That error should cause the process to exit and, consequently, the socket to close. |
Author
|
You're right, thanks for checking. The TypeError is uncaught and terminates the process; the "socket stays open" part of my description was wrong, sorry about that. As for the use case, I don't have a concrete user report. I found it while reading |
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.
If the
verifyClientcallback rejects a client with a status code that is not inhttp.STATUS_CODES(for examplecb(false, 499)),abortHandshake()throws:The error is thrown from inside the user's callback, and no response is written, so the socket stays open until the client gives up. If a message is passed (
cb(false, 499, 'Token expired')), the response is sent but the status line isHTTP/1.1 499 undefined.This change falls back to
Unknownas the reason phrase when the code is not inhttp.STATUS_CODES, similar to whathttp.ServerResponsedoes (HTTP/1.1 499 unknown). It also uses that phrase as the default body.For context, in ws 1.x the status line was built from the
nameargument ('HTTP/1.1 ' + code + ' ' + name), so custom codes worked. Since 3.x the reason phrase always comes fromhttp.STATUS_CODES[code].doc/ws.mdstill describesnameas "the HTTP reason phrase", although it is now used as the body. I left the docs and that behaviour alone here, but I can update the docs in this PR if you prefer.A test is added next to the existing "can reject client asynchronously w/ status code" test. Without the fix it fails with the
TypeErrorabove.This PR was generated with AI (Claude Code).