mirror of
https://github.com/curl/curl.git
synced 2025-02-17 14:59:45 +08:00
test2305: send 3 frames, 4097 bytes each, as one message
Receive them using a 256 bytes buffer in a loop.
This commit is contained in:
parent
2e2e3d16c5
commit
5a9a04d556
@ -77,6 +77,7 @@
|
||||
1943
|
||||
2301
|
||||
2302
|
||||
2305
|
||||
%endif
|
||||
2043
|
||||
# Tests that are disabled here for rustls are SUPPOSED to work
|
||||
|
@ -242,7 +242,7 @@ test2100 \
|
||||
\
|
||||
test2200 test2201 test2202 test2203 test2204 test2205 \
|
||||
\
|
||||
test2300 test2301 test2302 test2303 test2304 \
|
||||
test2300 test2301 test2302 test2303 test2304 test2305 \
|
||||
\
|
||||
test2400 test2401 test2402 \
|
||||
\
|
||||
|
59
tests/data/test2305
Normal file
59
tests/data/test2305
Normal file
@ -0,0 +1,59 @@
|
||||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
WebSockets
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
#
|
||||
# Sends three 4097 bytes TEXT frames, as one single message
|
||||
<reply>
|
||||
<data nocheck="yes">
|
||||
HTTP/1.1 101 Switching to WebSockets
|
||||
Server: test-server/fake
|
||||
Upgrade: websocket
|
||||
Connection: Upgrade
|
||||
Something: else
|
||||
Sec-WebSocket-Accept: HkPsVga7+8LuxM4RGQ5p9tZHeYs=
|
||||
|
||||
%hex[%01%7e%10%01]hex%%repeat[256 x helothisisdaniel]%
|
||||
%hex[%01%7e%10%01]hex%%repeat[256 x helothisisdaniel]%
|
||||
%hex[%81%7e%10%01]hex%%repeat[256 x helothisisdaniel]%
|
||||
</data>
|
||||
# allow upgrade
|
||||
<servercmd>
|
||||
upgrade
|
||||
</servercmd>
|
||||
</reply>
|
||||
|
||||
#
|
||||
# Client-side
|
||||
<client>
|
||||
# require debug for the forced CURL_ENTROPY
|
||||
<features>
|
||||
debug
|
||||
ws
|
||||
</features>
|
||||
<server>
|
||||
http
|
||||
</server>
|
||||
<name>
|
||||
WebSocket curl_ws_recv() loop reading three larger frames
|
||||
</name>
|
||||
<tool>
|
||||
lib%TESTNUMBER
|
||||
</tool>
|
||||
<command>
|
||||
ws://%HOSTIP:%HTTPPORT/%TESTNUMBER log/save%TESTNUMBER
|
||||
</command>
|
||||
</client>
|
||||
|
||||
#
|
||||
<verify>
|
||||
<file name="log/save%TESTNUMBER">
|
||||
%repeat[256 x helothisisdaniel]%
|
||||
%repeat[256 x helothisisdaniel]%
|
||||
%repeat[256 x helothisisdaniel]%
|
||||
</file>
|
||||
</verify>
|
||||
</testcase>
|
@ -69,7 +69,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \
|
||||
lib1915 lib1916 lib1917 lib1918 lib1919 \
|
||||
lib1933 lib1934 lib1935 lib1936 lib1937 lib1938 lib1939 lib1940 \
|
||||
lib1945 lib1946 lib1947 lib1948 lib1955 lib1956 lib1957 lib1958 lib1959 \
|
||||
lib2301 lib2302 lib2304 \
|
||||
lib2301 lib2302 lib2304 lib2305 \
|
||||
lib2402 \
|
||||
lib2502 \
|
||||
lib3010 lib3025 lib3026 lib3027 \
|
||||
@ -800,6 +800,9 @@ lib2302_LDADD = $(TESTUTIL_LIBS)
|
||||
lib2304_SOURCES = lib2304.c $(SUPPORTFILES)
|
||||
lib2304_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib2305_SOURCES = lib2305.c $(SUPPORTFILES) $(TESTUTIL) $(TSTTRACE)
|
||||
lib2305_LDADD = $(TESTUTIL_LIBS)
|
||||
|
||||
lib2402_SOURCES = lib2402.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
|
||||
lib2402_LDADD = $(TESTUTIL_LIBS)
|
||||
lib2402_CPPFLAGS = $(AM_CPPFLAGS) -DLIB2402
|
||||
|
106
tests/libtest/lib2305.c
Normal file
106
tests/libtest/lib2305.c
Normal file
@ -0,0 +1,106 @@
|
||||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* 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"
|
||||
#include "testtrace.h"
|
||||
|
||||
#ifdef USE_WEBSOCKETS
|
||||
|
||||
/* just close the connection */
|
||||
static void websocket_close(CURL *curl)
|
||||
{
|
||||
size_t sent;
|
||||
CURLcode result =
|
||||
curl_ws_send(curl, "", 0, &sent, 0, CURLWS_CLOSE);
|
||||
fprintf(stderr,
|
||||
"ws: curl_ws_send returned %u, sent %u\n", (int)result, (int)sent);
|
||||
}
|
||||
|
||||
static void websocket(CURL *curl)
|
||||
{
|
||||
char buffer[256];
|
||||
struct curl_ws_frame *meta;
|
||||
size_t nread;
|
||||
size_t i = 0;
|
||||
FILE *save = fopen(libtest_arg2, FOPEN_WRITETEXT);
|
||||
if(!save)
|
||||
return;
|
||||
|
||||
/* Three 4097-bytes frames are expected, 12291 bytes */
|
||||
while(i < 12291) {
|
||||
CURLcode result =
|
||||
curl_ws_recv(curl, buffer, sizeof(buffer), &nread, &meta);
|
||||
if(result) {
|
||||
printf("curl_ws_recv returned %d\n", (int)result);
|
||||
return;
|
||||
}
|
||||
printf("%u: nread %u Age %u Flags %x "
|
||||
"Offset %" CURL_FORMAT_CURL_OFF_T " "
|
||||
"Bytesleft %" CURL_FORMAT_CURL_OFF_T "\n",
|
||||
(int)i,
|
||||
nread, meta->age, meta->flags, meta->offset, meta->bytesleft);
|
||||
i += meta->len;
|
||||
fwrite(buffer, 1, nread, save);
|
||||
}
|
||||
fclose(save);
|
||||
|
||||
websocket_close(curl);
|
||||
}
|
||||
|
||||
extern struct libtest_trace_cfg libtest_debug_config;
|
||||
|
||||
int test(char *URL)
|
||||
{
|
||||
CURL *curl;
|
||||
CURLcode res = CURLE_OK;
|
||||
|
||||
global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, URL);
|
||||
|
||||
/* use the callback style */
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "websocket/2304");
|
||||
libtest_debug_config.nohex = 1;
|
||||
libtest_debug_config.tracetime = 1;
|
||||
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config);
|
||||
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
|
||||
res = curl_easy_perform(curl);
|
||||
fprintf(stderr, "curl_easy_perform() returned %u\n", (int)res);
|
||||
if(res == CURLE_OK)
|
||||
websocket(curl);
|
||||
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
#else
|
||||
NO_SUPPORT_BUILT_IN
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user