websocket: support CURLOPT_READFUNCTION

Add support for CURLOPT_READFUNCTION with WebSocket urls when *not* in
connect-only mode, e.g. when using curl_multi_perform.

Install the callback function and set CURLOPT_UPLOAD. Return
CURL_READFUNC_PAUSE when having nothing more to send and unpause the
transfer when more data is ready.

This will send the read bytes in a WebSocket BINARY frame.

Add support for this mode in the pytest "ws_data" client and have all
tests run in 'curl_ws_send/recv' and 'peform' mode as well.

Add `curl_ws_start_frame()`. Document, cover in libcurl-ws.md and
explain the READFUNCTION mode for websockets.

Add example `websocket-updown` for this.

Closes #17683
This commit is contained in:
Stefan Eissing 2025-07-08 09:15:43 +02:00 committed by Daniel Stenberg
parent 756c0718c2
commit 37cecfc7b9
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
17 changed files with 878 additions and 156 deletions

View file

@ -72,6 +72,19 @@ CURL_EXTERN CURLcode curl_ws_send(CURL *curl, const void *buffer,
curl_off_t fragsize,
unsigned int flags);
/*
* NAME curl_ws_start_frame()
*
* DESCRIPTION
*
* Buffers a websocket frame header with the given flags and length.
* Errors when a previous frame is not complete, e.g. not all its
* payload has been added.
*/
CURL_EXTERN CURLcode curl_ws_start_frame(CURL *curl,
unsigned int flags,
curl_off_t frame_len);
/* bits for the CURLOPT_WS_OPTIONS bitmask: */
#define CURLWS_RAW_MODE (1L<<0)
#define CURLWS_NOAUTOPONG (1L<<1)