[minor] added --print-reason cli argument for ws close reason #109
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.
intended to solve #108
functionality
when using
-r
or--print-reason
, when the ws closes and the server sends a reason string, the console will exit withDisconnected (code: 4001, reason: some reason)
instead of the currentDisconnected (code: 4001)
.This is opt-in, to keep the change minor.
display considerations
Maybe we want to give even more space to the reason, and bring it in its own line, without wrapping it in brackets, as the server might send a multi-line reason
implementation considerations
I've implemented this as a method of
wsConsole
to avoid code duplication, but it doesn't feel like it would belong there. Having a helper function to do this would need to havewsConsole
passed to it, as the disconnect message is sent in two places that reference differentwsConsole
s. I tend to avoidf(obj, ..params)
when almost everywhereobj.f(...params)
is used. I'll leave this up for discussion.security considerations
Currently
reason
is simply injected into the string to print, it's not sanitized by me. At best this means the server can change colors or ring bells in your terminal when the ws closes, at worst it could open the user up to remote code execution, depending on their terminal.Maybe this is fine, as wscat is mostly a debugging tool for APIs that you don't tend to consider malign. If it's not, I don't have in mind a best strategy to sanitize for all terminals other than only keeping ascii printable characters, or JSON.stringifying the whole string