websocket: new --ws-text, --ws-binary options, change implicit default to websocket text frames#22093
websocket: new --ws-text, --ws-binary options, change implicit default to websocket text frames#22093zmajeed wants to merge 5 commits into
Conversation
New --ws-text option sets text frames as default websocket frame type. Similarly --ws-binary sets the default to binary frames. The default frame type is text if neither option is given. The last option wins if both --ws-text and --ws-binary are given. Reported-by: Zartaj Majeed Fixes curl#21997
| BIT(ws_text_frames); /* true if default is text frames */ | ||
| /* false if default is binary frames */ |
There was a problem hiding this comment.
| BIT(ws_text_frames); /* true if default is text frames */ | |
| /* false if default is binary frames */ | |
| BIT(ws_text_frames); |
being a bit and the name of the variable explains this already
IMO. Seems overkill to me to reiterate this in two comments.
There was a problem hiding this comment.
While it's true that a client frame is either text or binary, I just don't find the naming to patently suggest that. I like the comment because it clearly states what !ws_text_frames means and I'll never need to go look in the code where it's used to figure out that it is indeed binary frames.
There was a problem hiding this comment.
If a non-text frame can be any other than binary, then
perhaps this should not be a bit, but an enum/int. Short
of that, I still see these comments adding no information.
There was a problem hiding this comment.
The comment minimally and plainly makes it clear ws_text_frames false means binary frames are default - something the name and type of the variable itself doesn't tell you unless you already know its background -- think as a developer looking at this variable and websocket code for the first time - would you resent or appreciate the contextual info?
There's also the benefit of getting a hit here for simple grep and search for "binary frames" or "binary"
| - --ws-text -o storage $URL | ||
| --- | ||
|
|
||
| # `--ws-text` |
There was a problem hiding this comment.
Since binary is the current default, and this PR aims to introduce
text mode over that, and because the two are mutually exclusive
and reverse of each other, would it make sense to introduce just
one new option: --ws-text and support the --no-ws-text
as its reverse, like its done with other existing boolean options?
There was a problem hiding this comment.
This point was raised in the issue too. I really prefer obvious option names to something implied or that relies on pre-knowledge. To me --no-ws-text doesn't obviously mean binary frames. Sure it could be documented that way. But if I put myself in the shoes of a casual user or even a user who wants to use curl for websocket without knowing much or anything about the protocol specs. Seeing just --ws-text and nothing else won't tell me about the possibility of binary frames - also this thing with --no- prefix might be well-known to you and regular curl users but I bet a lot of people don't know about --no- or don't know which options allow it.
I brought up websocat earlier - I think it's useful to look at what websocat has done - it's a popular tool and despite being made just for websocket and nothing else, it still gives separate text and binary options.
I think the bottom line of this debate is I don't see the names as boolean opposites - even though I agree they are mutually exclusive in effect - it's just the plain upfront affirmative naming that works for me compared to a negated option name that implies the other name
There was a problem hiding this comment.
Can it be any other format in the future? If it can be I could see
a point in spelling out the exact format in the option (instead
of rolling a separate option for each), but in such case perhaps
it should be an argument, such as --ws=binary (or similar).
This may even be more future proof to do now, just in case
there will be more format variations in the future.
(I don't believe that looking at naming conventions used
in other tools help in general. Names may be heavily dependent
on context and other existing conventions in each specifc tool.)
There was a problem hiding this comment.
The two separate options is the most user-friendly choice
A frame-type or mode option is not as user-friendly because it's longer, involves values, requires an extra docs and mental lookup to know what the values are and their syntax
Similarly for text + no-text, just not as user-friendly and ergonomic, because it hides the word binary and requires extra knowledge of curl options syntax
The naming convention is straight from the spec - the choice of separate options is just ergonomics and being considerate of users
I mention websocat because it's a good tool with good options that has held up over time - its choices reflect its users experience with doing commandline websocket messages - it's not particularly about looking at another tool but about looking at what the people using that tool to solve the same problem have come to like or dislike
|
Analysis of PR #22093 at f1375373: Test 1139 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 156 different CI jobs (the link just goes to one of them). Test 1119 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 144 different CI jobs (the link just goes to one of them). Test 971 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 213 different CI jobs (the link just goes to one of them). Test 1478 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Note that this test has failed in 137 different CI jobs (the link just goes to one of them). Test 2727 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Test 2724 failed, which has NOT been flaky recently, so there could be a real issue in this PR. Test 2725 failed, which has NOT been flaky recently, so there could be a real issue in this PR. There are more failures, but that's enough from Gha. Generated by Testclutch |
|
There's an awful lot of CI failures that I find hard to believe have anything to do with my changes - is testclutch bot to be believed when it says none of these tests are flaky? |
|
None of those failing tests are found in the recent test failures list so it's very likely they're related to this PR, especially since most of them are causing failures in multiple CI jobs. |
| #endif | ||
| } | ||
| my_setopt_long(curl, CURLOPT_UPLOAD_FLAGS, config->upload_flags); | ||
| #ifndef CURL_DISABLE_WEBSOCKETS |
There was a problem hiding this comment.
We try to keep protocol disable/enable limited to libcurl only, so that the tool works with libcurl builds independently of those. IOW: the tool always knows about WebSocket.
|
|
||
| # `--ws-binary` | ||
|
|
||
| Tell curl to send websocket binary frames by default. This option and the related `--ws-text` option determine the type of frame sent by curl to a websocket server. If neither option is given, the default is to send text frames. If both options are used, the last one wins. |
There was a problem hiding this comment.
We use the official casing of the protocol name:
| Tell curl to send websocket binary frames by default. This option and the related `--ws-text` option determine the type of frame sent by curl to a websocket server. If neither option is given, the default is to send text frames. If both options are used, the last one wins. | |
| Tell curl to send WebSocket binary frames by default. This option and the related `--ws-text` option determine the type of frame sent by curl to a WebSocket server. If neither option is given, the default is to send text frames. If both options are used, the last one wins. |
There was a problem hiding this comment.
Should websocket options be a new websocket help category? Went ahead and made a new category
|
ok - I see the same thing failing in many checks - something about symbols in sync, manpages - what is this and how do I fix it? |
|
I propose you run them one by one and check |
|
this comment in is there a way to make it work for out-of-tree builds? Or do I hack the makefile? |
|
nvm, looks like I have to run managen manually for each case |
|
similar to difficulty of running runtests.pl directly for out-of-tree builds - make test works but sets |
…ptions to docs makefile, run manual commands to generate docs code
|
Not getting this function size check for config2setopts - I added 4 simple lines to an already long function - is it simply the straw the broke its back? |
|
Waiting on some advice on what to do with config2setopts length - should the function be broken into smaller pieces for each group of options so it's not teetering on triggering this failure every time - or are my 4 lines really that complicated that I have to find an alternative |
|
Maybe we can use Similarly it would probably make sense to reuse |
|
I think my perspective is of a new user who's looking at curl for websocket features - I'd prefer to not dig through legacy options that might or might not be useful for websocket - old option names won't be meaningful when read from websocket commandlines - yes Is it that curl is never expected to support websocket options? If so then I could understand the opposition to the new options - otherwise why not give websocket a good first-class citizen start? |
This is a WebSocket option we're talking about. |
|
What I meant is curl is never expected to have a websocket category of options - no Since that's the case, I'll close my PR - and let you guys come up with a resolution to the issue |
ever is a long time. It would probably be foolish of us to make absolute statements of what kind of options we might add in a future. If we feel we need such options and someone implements them, I can imagine we add some. But our job is to always make sure we first try to avoid adding new options. |
|
No worries - I'm happy with websocat - I'll close the PR now - should I close the issue too? |
|
closing, no cigar |
Two new options
--ws-textand--ws-binaryhave been added to set websocket frames to text and binary respectively. The implicit default has been changed to text frames if neither option is given. Previously the default was binary frames.Both options are documented. Four tests have been added for various combinations of the new options
I've gone for the simplest change - replacing the hardcoded
CURLWS_BINARYincr_ws_readwith the frame type indicated byws_text_framesinCurl_easyoptionsAll other changes are boilerplate for adding new options. I did add
CURLOPT_WS_OPTIONStotool_setopt.cso I could usemy_setopt_bitmaskinconfig2setopts.cThe new options correspond to a new enum in
tool_cfgable.h- I prefer this to a boolean flagLet me make a case for changing the implicit default for websocket frames to text from binary frames
Given all of the above, I feel it's better to go with the better default now even if it means breaking compatibility.
Fixes #21997