mirror of
https://github.com/curl/curl.git
synced 2026-07-29 23:28:08 +03:00
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:
parent
21fd64645b
commit
c0df01fd94
15 changed files with 204 additions and 9 deletions
|
|
@ -1384,7 +1384,8 @@ static CURLcode setopt_long(struct Curl_easy *data, CURLoption option,
|
|||
#endif /* ! CURL_DISABLE_ALTSVC */
|
||||
#ifndef CURL_DISABLE_WEBSOCKETS
|
||||
case CURLOPT_WS_OPTIONS:
|
||||
data->set.ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE);
|
||||
data->set.ws_raw_mode = (bool)(arg & CURLWS_RAW_MODE);
|
||||
data->set.ws_no_auto_pong = (bool)(arg & CURLWS_NOAUTOPONG);
|
||||
break;
|
||||
#endif
|
||||
case CURLOPT_QUICK_EXIT:
|
||||
|
|
|
|||
|
|
@ -480,6 +480,11 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data)
|
|||
memset(&set->priority, 0, sizeof(set->priority));
|
||||
#endif
|
||||
set->quick_exit = 0L;
|
||||
#ifndef CURL_DISABLE_WEBSOCKETS
|
||||
set->ws_raw_mode = FALSE;
|
||||
set->ws_no_auto_pong = FALSE;
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1802,6 +1802,7 @@ struct UserDefined {
|
|||
BIT(http09_allowed); /* allow HTTP/0.9 responses */
|
||||
#ifndef CURL_DISABLE_WEBSOCKETS
|
||||
BIT(ws_raw_mode);
|
||||
BIT(ws_no_auto_pong);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
|||
8
lib/ws.c
8
lib/ws.c
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue