mirror of
https://github.com/curl/curl.git
synced 2026-08-12 01:20:52 +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
|
|
@ -259,7 +259,7 @@ test2100 test2101 test2102 \
|
|||
test2200 test2201 test2202 test2203 test2204 test2205 \
|
||||
\
|
||||
test2300 test2301 test2302 test2303 test2304 test2305 test2306 test2307 \
|
||||
test2308 test2309 test2310 test2311 \
|
||||
test2308 test2309 test2310 test2311 test2312 \
|
||||
\
|
||||
test2400 test2401 test2402 test2403 test2404 test2405 test2406 \
|
||||
\
|
||||
|
|
|
|||
66
tests/data/test2312
Normal file
66
tests/data/test2312
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
WebSockets
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
#
|
||||
# Server-side
|
||||
<reply>
|
||||
<data nocheck="yes" nonewline="yes">
|
||||
HTTP/1.1 101 Switching to WebSockets swsclose
|
||||
Server: test-server/fake
|
||||
Upgrade: websocket
|
||||
Connection: Upgrade
|
||||
Sec-WebSocket-Accept: HkPsVga7+8LuxM4RGQ5p9tZHeYs=
|
||||
|
||||
%hex[%89%00]hex%
|
||||
</data>
|
||||
# allow upgrade
|
||||
<servercmd>
|
||||
upgrade
|
||||
</servercmd>
|
||||
</reply>
|
||||
|
||||
#
|
||||
# Client-side
|
||||
<client>
|
||||
# for the forced CURL_ENTROPY
|
||||
<features>
|
||||
debug
|
||||
ws
|
||||
</features>
|
||||
<server>
|
||||
http
|
||||
</server>
|
||||
<name>
|
||||
WebSockets no auto ping
|
||||
</name>
|
||||
<tool>
|
||||
lib%TESTNUMBER
|
||||
</tool>
|
||||
<command>
|
||||
ws://%HOSTIP:%HTTPPORT/%TESTNUMBER
|
||||
</command>
|
||||
</client>
|
||||
|
||||
#
|
||||
# Verify data after the test has been "shot"
|
||||
<verify>
|
||||
<protocol nocheck="yes">
|
||||
GET /%TESTNUMBER HTTP/1.1
|
||||
Host: %HOSTIP:%HTTPPORT
|
||||
User-Agent: webbie-sox/3
|
||||
Accept: */*
|
||||
Upgrade: websocket
|
||||
Connection: Upgrade
|
||||
Sec-WebSocket-Version: 13
|
||||
Sec-WebSocket-Key: NDMyMTUzMjE2MzIxNzMyMQ==
|
||||
|
||||
</protocol>
|
||||
<errorcode>
|
||||
0
|
||||
</errorcode>
|
||||
</verify>
|
||||
</testcase>
|
||||
|
|
@ -74,7 +74,7 @@ LIBTESTPROGS = libauthretry libntlmconnect libprereq \
|
|||
lib1960 lib1964 \
|
||||
lib1970 lib1971 lib1972 lib1973 lib1974 lib1975 lib1977 lib1978 \
|
||||
lib2301 lib2302 lib2304 lib2305 lib2306 lib2308 lib2309 lib2310 \
|
||||
lib2311 \
|
||||
lib2311 lib2312 \
|
||||
lib2402 lib2404 lib2405 \
|
||||
lib2502 \
|
||||
lib3010 lib3025 lib3026 lib3027 \
|
||||
|
|
@ -713,6 +713,9 @@ lib2310_LDADD = $(TESTUTIL_LIBS)
|
|||
lib2311_SOURCES = lib2311.c $(SUPPORTFILES) $(TESTUTIL) $(TSTTRACE) $(MULTIBYTE)
|
||||
lib2311_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib2312_SOURCES = lib2312.c $(SUPPORTFILES) $(TESTUTIL) $(TSTTRACE) $(MULTIBYTE)
|
||||
lib2312_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib2402_SOURCES = lib2402.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
|
||||
lib2402_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
|
|
|
|||
102
tests/libtest/lib2312.c
Normal file
102
tests/libtest/lib2312.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#ifdef USE_WEBSOCKETS
|
||||
|
||||
struct ping_check {
|
||||
CURL *curl;
|
||||
int pinged;
|
||||
};
|
||||
|
||||
static size_t write_cb(char *b, size_t size, size_t nitems, void *p)
|
||||
{
|
||||
struct ping_check *ping_check = p;
|
||||
CURL *curl = ping_check->curl;
|
||||
const struct curl_ws_frame *frame = curl_ws_meta(curl);
|
||||
size_t sent = 0;
|
||||
size_t i = 0;
|
||||
|
||||
/* upon ping, respond with input data, disconnect, mark a success */
|
||||
if(frame->flags & CURLWS_PING) {
|
||||
fprintf(stderr, "write_cb received ping with %zd bytes\n",
|
||||
size * nitems);
|
||||
fprintf(stderr, "\n");
|
||||
for(i = 0; i < size * nitems; i++) {
|
||||
fprintf(stderr, "%02X%s", (int)b[i],
|
||||
(i % 10 == 0 && i != 0) ? "\n" : " ");
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "write_cb sending pong response\n");
|
||||
curl_ws_send(curl, b, size * nitems, &sent, 0, CURLWS_PONG);
|
||||
fprintf(stderr, "write_cb closing websocket\n");
|
||||
curl_ws_send(curl, NULL, 0, &sent, 0, CURLWS_CLOSE);
|
||||
ping_check->pinged = 1;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "ping_check_cb: non-ping message, frame->flags %x\n",
|
||||
frame->flags);
|
||||
}
|
||||
|
||||
return size * nitems;
|
||||
}
|
||||
|
||||
CURLcode test(char *URL)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
struct ping_check state;
|
||||
|
||||
global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
state.curl = curl;
|
||||
state.pinged = 0;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, URL);
|
||||
|
||||
/* use the callback style, without auto-pong */
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3");
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_WS_OPTIONS, (long)CURLWS_NOAUTOPONG);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &state);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
fprintf(stderr, "curl_easy_perform() returned %u\n", (int)res);
|
||||
|
||||
res = state.pinged ? 0 : 1;
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return res;
|
||||
}
|
||||
|
||||
#else /* no websockets */
|
||||
NO_SUPPORT_BUILT_IN
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue