websocket: add option to disable auto-pong reply

This adds another bitflag on CURLOPT_WS_OPTIONS (CURLWS_NOAUTOPONG) that
disables the default and automatic PONG reply in the WebSocket layer.

Assisted-by: Calvin Ruocco

Closes #16744
This commit is contained in:
Brian Chrzanowski 2024-07-23 22:15:23 -04:00 committed by Daniel Stenberg
parent 21fd64645b
commit c0df01fd94
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
15 changed files with 204 additions and 9 deletions

View file

@ -502,10 +502,12 @@ static ssize_t ws_cw_dec_next(const unsigned char *buf, size_t buflen,
struct ws_cw_dec_ctx *ctx = user_data;
struct Curl_easy *data = ctx->data;
struct websocket *ws = ctx->ws;
bool auto_pong = !data->set.ws_no_auto_pong;
curl_off_t remain = (payload_len - (payload_offset + buflen));
(void)frame_age;
if((frame_flags & CURLWS_PING) && !remain) {
if(auto_pong && (frame_flags & CURLWS_PING) && !remain) {
/* auto-respond to PINGs, only works for single-frame payloads atm */
size_t bytes;
infof(data, "WS: auto-respond to PING with a PONG");
@ -949,6 +951,8 @@ static ssize_t ws_client_collect(const unsigned char *buf, size_t buflen,
CURLcode *err)
{
struct ws_collect *ctx = userp;
struct Curl_easy *data = ctx->data;
bool auto_pong = !data->set.ws_no_auto_pong;
size_t nwritten;
curl_off_t remain = (payload_len - (payload_offset + buflen));
@ -960,7 +964,7 @@ static ssize_t ws_client_collect(const unsigned char *buf, size_t buflen,
ctx->payload_len = payload_len;
}
if((frame_flags & CURLWS_PING) && !remain) {
if(auto_pong && (frame_flags & CURLWS_PING) && !remain) {
/* auto-respond to PINGs, only works for single-frame payloads atm */
size_t bytes;
infof(ctx->data, "WS: auto-respond to PING with a PONG");