From f61706cbac43e2eef41e90ef98326cebec5a4d54 Mon Sep 17 00:00:00 2001 From: Stefan Eissing Date: Thu, 31 Jul 2025 11:26:12 +0200 Subject: [PATCH] In CURLWS_RAW_MODE, to not add an encoding reader, so clients can send raw frames. --- docs/libcurl/opts/CURLOPT_WS_OPTIONS.md | 1 + lib/ws.c | 27 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/docs/libcurl/opts/CURLOPT_WS_OPTIONS.md b/docs/libcurl/opts/CURLOPT_WS_OPTIONS.md index 35ae17cf47..998fb16f09 100644 --- a/docs/libcurl/opts/CURLOPT_WS_OPTIONS.md +++ b/docs/libcurl/opts/CURLOPT_WS_OPTIONS.md @@ -39,6 +39,7 @@ Available bits in the bitmask ## CURLWS_RAW_MODE (1) Deliver "raw" WebSocket traffic to the CURLOPT_WRITEFUNCTION(3) +callback. Read "raw" WebSocket traffic from the CURLOPT_READFUNCTION(3) callback. In raw mode, libcurl does not handle pings or any other frame for the diff --git a/lib/ws.c b/lib/ws.c index 7217edc158..55579b7fde 100644 --- a/lib/ws.c +++ b/lib/ws.c @@ -1185,15 +1185,17 @@ CURLcode Curl_ws_accept(struct Curl_easy *data, if(result) goto out; - /* Add our client readerr encoding WS BINARY frames */ - result = Curl_creader_create(&ws_enc_reader, data, &ws_cr_encode, - CURL_CR_CONTENT_ENCODE); - if(result) - goto out; - result = Curl_creader_add(data, ws_enc_reader); - if(result) - goto out; - ws_enc_reader = NULL; /* owned by transfer now */ + if(!data->set.ws_raw_mode) { + /* Add our client readerr encoding WS BINARY frames */ + result = Curl_creader_create(&ws_enc_reader, data, &ws_cr_encode, + CURL_CR_CONTENT_ENCODE); + if(result) + goto out; + result = Curl_creader_add(data, ws_enc_reader); + if(result) + goto out; + ws_enc_reader = NULL; /* owned by transfer now */ + } /* start over with sending */ data->req.eos_read = FALSE; @@ -1723,6 +1725,13 @@ CURL_EXTERN CURLcode curl_ws_start_frame(CURL *d, CURLcode result = CURLE_OK; struct Curl_easy *data = d; + if(!GOOD_EASY_HANDLE(data)) + return CURLE_BAD_FUNCTION_ARGUMENT; + if(data->set.ws_raw_mode) { + failf(data, "cannot curl_ws_start_frame() with CURLWS_RAW_MODE enabled"); + return CURLE_FAILED_INIT; + } + CURL_TRC_WS(data, "curl_start_frame(flags=%x, frame_len=%" FMT_OFF_T, flags, frame_len);