websocket: support CURLOPT_READFUNCTION#17683
Closed
icing wants to merge 3 commits intocurl:masterfrom
Closed
Conversation
Closed
Member
|
This branch has conflicts that must be resolved |
bagder
approved these changes
Jul 30, 2025
Member
|
this branch has conflicts ... |
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.
Contributor
Author
|
I wonder if we should add a Update: on second thought, let's do this if someone really needs it. |
bagder
approved these changes
Aug 11, 2025
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.
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. For other frame types, add a new API function:
Add an example using
CURLOPT_READFUNCTIONandcurl_ws_start_frame()indocs/examples/websocket-updown.c.Add support for this mode in the pytest "ws_data" client and have all tests run in 'curl_ws_send/recv' and 'perform' mode as well.
This allows on the command line to "talk" to an echo server:
so
stdinandstdoutare the websocket connection with auto-en- and decoding. Forlibcurlusers, they can multi handle many such websocket transfers and haveREADFUNCTIONandWRITEFUNCTIONto do with the data whatever they like.Update: when
CURLWS_RAW_MODEis set for the transfer, the websocket encoding client reader is not installed and theCURLOPT_READFUNCTIONcan add raw websocket frames.