curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Sending a fragmented WebSocket message.

From: Paul Fotheringham via curl-library <curl-library_at_lists.haxx.se>
Date: Mon, 18 Sep 2023 23:56:58 +0100

Following on from my post about detecting the final frame of a
fragmented WebSocket message there is also an issue sending fragmented
messages.

I cannot figure out the flags that you are meant to set when calling
curl_ws_send with each fragment and I suspect there is no correct
combination.

Looking at the code ws_enc_write_head makes a call to
ws_frame_flags2op to convert the supplied flags to an opcode. Now if
flags contains CURLWS_CONT (4) then ws_frame_flags2op will return zero
regardless of any other flags that are ORed with it. This return value
is assigned to opcode but the very next bit of code returns
CURLE_SEND_ERROR if (!opcode).

Adding to the confusion is the fact that the 4-bit opcode in the first
byte of the WebSocket header is not a bit-field despite the CURLWS_*
defines suggesting it is.

I propose
- changing the CURLWS_TEXT thru CURLWS_PING defines to be their actual
numerical 4-bit values
- rename the curl_ws_send's flags argument to opcode
- add an argument to curl_ws_send to replace the CURLWS_OFFSET functionality
- add libtest cases to cover csl_ws_send for non-control frames
-- libtest 2303 claims to test curl_ws_send but the code is missing to
actually send a (unfragmneted) text frame
-- add a libtest for sending a fragmented text frame, not sure how to
verify the data server-size though
- add a libtest for sending a frame in pieces i.e. the CURLWS_OFFSET
functionality

Paul
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-09-19