2023-04-26 12:38:22 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
* _ _ ____ _
|
|
|
|
|
* 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
|
|
|
|
|
*
|
|
|
|
|
***************************************************************************/
|
2025-06-22 01:10:59 +02:00
|
|
|
#include "first.h"
|
2023-04-26 12:38:22 +02:00
|
|
|
|
tests: merge clients into libtests, drop duplicate code
libtests and clients were built the same way after recent overhauls.
libtests are used by runtests, clients by pytests.
Merge clients into libtests, aligning their entry function signature,
dropping common utility functions, and simplifying the build.
Note: After this patch `CURLDEBUG` applies to cli tests, when enabled.
Also:
- lib552: drop local copy-paste debug callback in favor of testtrace.
- lib552: drop local copy-paste dump function in favor of testtrace.
- clients: use `long` for HTTP version, drop casts.
- clients: replace local dump function in favor of testrace clone.
- sync cli test entry function prototype with libtests'.
- h2_serverpush: replace local trace callback with testtrace.
- de-duplicate 3 websocket close, ping, ping, functions. Kept the pong
iteration from `ws_pingpong`. Note: the pong clone in `lib2304` was
returning an error when `curl_ws_recv()` returned non-zero and
the payload matched the expected one anyway. After this patch, this
case returns success, as it does in `ws_pingpong`.
`lib2304` keeps passing, but I'm not sure if the previous behavior
was intentional.
- display full value in websocket close, ping, pong, drop casts.
Closes #18079
2025-07-29 09:53:14 +02:00
|
|
|
#include "testtrace.h"
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-10-31 17:36:27 +01:00
|
|
|
static FILE *out_download = NULL;
|
2025-06-22 10:18:12 +02:00
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
static int setup_h2_serverpush(CURL *curl, const char *url)
|
2023-04-26 12:38:22 +02:00
|
|
|
{
|
2025-09-14 15:34:18 +02:00
|
|
|
out_download = curlx_fopen("download_0.data", "wb");
|
2025-06-22 10:18:12 +02:00
|
|
|
if(!out_download)
|
|
|
|
|
return 1; /* failed */
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_download);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
|
|
|
|
/* please be verbose */
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
|
|
|
|
/* wait for pipe connection to confirm */
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
|
2025-06-15 14:48:46 +02:00
|
|
|
|
2023-04-26 12:38:22 +02:00
|
|
|
return 0; /* all is good */
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 17:36:27 +01:00
|
|
|
static FILE *out_push = NULL;
|
2025-06-22 10:18:12 +02:00
|
|
|
|
2025-10-31 03:33:14 +01:00
|
|
|
/* called when there is an incoming push */
|
2023-04-26 12:38:22 +02:00
|
|
|
static int server_push_callback(CURL *parent,
|
2025-10-31 18:36:43 +01:00
|
|
|
CURL *curl,
|
2023-04-26 12:38:22 +02:00
|
|
|
size_t num_headers,
|
|
|
|
|
struct curl_pushheaders *headers,
|
|
|
|
|
void *userp)
|
|
|
|
|
{
|
2026-02-01 03:57:45 +01:00
|
|
|
const char *headp;
|
2023-04-26 12:38:22 +02:00
|
|
|
size_t i;
|
|
|
|
|
int *transfers = (int *)userp;
|
|
|
|
|
char filename[128];
|
|
|
|
|
static unsigned int count = 0;
|
|
|
|
|
|
2025-09-02 13:20:20 +02:00
|
|
|
(void)parent;
|
2025-10-31 03:33:14 +01:00
|
|
|
|
2025-06-22 10:18:12 +02:00
|
|
|
curl_msnprintf(filename, sizeof(filename) - 1, "push%u", count++);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
|
|
|
|
/* here's a new stream, save it in a new file for each new push */
|
2025-09-14 15:34:18 +02:00
|
|
|
out_push = curlx_fopen(filename, "wb");
|
2025-06-22 10:18:12 +02:00
|
|
|
if(!out_push) {
|
2023-04-26 12:38:22 +02:00
|
|
|
/* if we cannot save it, deny it */
|
2025-06-17 19:57:28 +02:00
|
|
|
curl_mfprintf(stderr, "Failed to create output file for push\n");
|
2025-10-31 03:33:14 +01:00
|
|
|
return CURL_PUSH_DENY;
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* write to this file */
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_push);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-06-17 19:57:28 +02:00
|
|
|
curl_mfprintf(stderr, "**** push callback approves stream %u, "
|
2025-07-30 02:12:22 +02:00
|
|
|
"got %zu headers!\n", count, num_headers);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2024-09-18 15:29:51 +02:00
|
|
|
for(i = 0; i < num_headers; i++) {
|
2023-04-26 12:38:22 +02:00
|
|
|
headp = curl_pushheader_bynum(headers, i);
|
2025-07-30 02:12:22 +02:00
|
|
|
curl_mfprintf(stderr, "**** header %zu: %s\n", i, headp);
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
headp = curl_pushheader_byname(headers, ":path");
|
|
|
|
|
if(headp) {
|
2025-06-17 19:57:28 +02:00
|
|
|
curl_mfprintf(stderr, "**** The PATH is %s\n",
|
|
|
|
|
headp /* skip :path + colon */);
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(*transfers)++; /* one more */
|
|
|
|
|
|
2025-10-31 03:33:14 +01:00
|
|
|
return CURL_PUSH_OK;
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Download a file over HTTP/2, take care of server push.
|
|
|
|
|
*/
|
tests: merge clients into libtests, drop duplicate code
libtests and clients were built the same way after recent overhauls.
libtests are used by runtests, clients by pytests.
Merge clients into libtests, aligning their entry function signature,
dropping common utility functions, and simplifying the build.
Note: After this patch `CURLDEBUG` applies to cli tests, when enabled.
Also:
- lib552: drop local copy-paste debug callback in favor of testtrace.
- lib552: drop local copy-paste dump function in favor of testtrace.
- clients: use `long` for HTTP version, drop casts.
- clients: replace local dump function in favor of testrace clone.
- sync cli test entry function prototype with libtests'.
- h2_serverpush: replace local trace callback with testtrace.
- de-duplicate 3 websocket close, ping, ping, functions. Kept the pong
iteration from `ws_pingpong`. Note: the pong clone in `lib2304` was
returning an error when `curl_ws_recv()` returned non-zero and
the payload matched the expected one anyway. After this patch, this
case returns success, as it does in `ws_pingpong`.
`lib2304` keeps passing, but I'm not sure if the previous behavior
was intentional.
- display full value in websocket close, ping, pong, drop casts.
Closes #18079
2025-07-29 09:53:14 +02:00
|
|
|
static CURLcode test_cli_h2_serverpush(const char *URL)
|
2023-04-26 12:38:22 +02:00
|
|
|
{
|
2025-10-31 18:36:43 +01:00
|
|
|
CURL *curl = NULL;
|
|
|
|
|
CURLM *multi;
|
2023-04-26 12:38:22 +02:00
|
|
|
int transfers = 1; /* we start with one */
|
2025-12-16 13:40:02 +01:00
|
|
|
CURLcode result = CURLE_OK;
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-07-30 02:12:22 +02:00
|
|
|
debug_config.nohex = TRUE;
|
|
|
|
|
debug_config.tracetime = FALSE;
|
tests: merge clients into libtests, drop duplicate code
libtests and clients were built the same way after recent overhauls.
libtests are used by runtests, clients by pytests.
Merge clients into libtests, aligning their entry function signature,
dropping common utility functions, and simplifying the build.
Note: After this patch `CURLDEBUG` applies to cli tests, when enabled.
Also:
- lib552: drop local copy-paste debug callback in favor of testtrace.
- lib552: drop local copy-paste dump function in favor of testtrace.
- clients: use `long` for HTTP version, drop casts.
- clients: replace local dump function in favor of testrace clone.
- sync cli test entry function prototype with libtests'.
- h2_serverpush: replace local trace callback with testtrace.
- de-duplicate 3 websocket close, ping, ping, functions. Kept the pong
iteration from `ws_pingpong`. Note: the pong clone in `lib2304` was
returning an error when `curl_ws_recv()` returned non-zero and
the payload matched the expected one anyway. After this patch, this
case returns success, as it does in `ws_pingpong`.
`lib2304` keeps passing, but I'm not sure if the previous behavior
was intentional.
- display full value in websocket close, ping, pong, drop casts.
Closes #18079
2025-07-29 09:53:14 +02:00
|
|
|
|
|
|
|
|
if(!URL) {
|
2025-06-17 19:57:28 +02:00
|
|
|
curl_mfprintf(stderr, "need URL as argument\n");
|
tests: merge clients into libtests, drop duplicate code
libtests and clients were built the same way after recent overhauls.
libtests are used by runtests, clients by pytests.
Merge clients into libtests, aligning their entry function signature,
dropping common utility functions, and simplifying the build.
Note: After this patch `CURLDEBUG` applies to cli tests, when enabled.
Also:
- lib552: drop local copy-paste debug callback in favor of testtrace.
- lib552: drop local copy-paste dump function in favor of testtrace.
- clients: use `long` for HTTP version, drop casts.
- clients: replace local dump function in favor of testrace clone.
- sync cli test entry function prototype with libtests'.
- h2_serverpush: replace local trace callback with testtrace.
- de-duplicate 3 websocket close, ping, ping, functions. Kept the pong
iteration from `ws_pingpong`. Note: the pong clone in `lib2304` was
returning an error when `curl_ws_recv()` returned non-zero and
the payload matched the expected one anyway. After this patch, this
case returns success, as it does in `ws_pingpong`.
`lib2304` keeps passing, but I'm not sure if the previous behavior
was intentional.
- display full value in websocket close, ping, pong, drop casts.
Closes #18079
2025-07-29 09:53:14 +02:00
|
|
|
return (CURLcode)2;
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-31 17:36:27 +01:00
|
|
|
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
|
|
|
|
|
curl_mfprintf(stderr, "curl_global_init() failed\n");
|
|
|
|
|
return (CURLcode)3;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
multi = curl_multi_init();
|
|
|
|
|
if(!multi) {
|
2025-12-16 13:40:02 +01:00
|
|
|
result = (CURLcode)1;
|
2025-10-31 17:36:27 +01:00
|
|
|
goto cleanup;
|
|
|
|
|
}
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
curl = curl_easy_init();
|
|
|
|
|
if(!curl) {
|
2025-12-16 13:40:02 +01:00
|
|
|
result = (CURLcode)1;
|
2025-10-31 17:36:27 +01:00
|
|
|
goto cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
if(setup_h2_serverpush(curl, URL)) {
|
2025-06-17 19:57:28 +02:00
|
|
|
curl_mfprintf(stderr, "failed\n");
|
2025-12-16 13:40:02 +01:00
|
|
|
result = (CURLcode)1;
|
2025-10-31 17:36:27 +01:00
|
|
|
goto cleanup;
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
|
|
|
|
|
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, server_push_callback);
|
|
|
|
|
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &transfers);
|
2025-10-31 03:33:14 +01:00
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_multi_add_handle(multi, curl);
|
2025-10-31 03:33:14 +01:00
|
|
|
|
2023-04-26 12:38:22 +02:00
|
|
|
do {
|
2025-10-31 03:33:14 +01:00
|
|
|
struct CURLMsg *m;
|
2023-04-26 12:38:22 +02:00
|
|
|
int still_running; /* keep number of running handles */
|
2025-12-16 13:40:02 +01:00
|
|
|
CURLMcode mresult = curl_multi_perform(multi, &still_running);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
|
|
|
|
if(still_running)
|
|
|
|
|
/* wait for activity, timeout or "nothing" */
|
2025-12-16 13:40:02 +01:00
|
|
|
mresult = curl_multi_poll(multi, NULL, 0, 1000, NULL);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-12-16 13:40:02 +01:00
|
|
|
if(mresult)
|
2023-04-26 12:38:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A little caution when doing server push is that libcurl itself has
|
|
|
|
|
* created and added one or more easy handles but we need to clean them up
|
|
|
|
|
* when we are done.
|
|
|
|
|
*/
|
|
|
|
|
do {
|
|
|
|
|
int msgq = 0;
|
2025-10-31 18:36:43 +01:00
|
|
|
m = curl_multi_info_read(multi, &msgq);
|
2023-04-26 12:38:22 +02:00
|
|
|
if(m && (m->msg == CURLMSG_DONE)) {
|
2025-10-31 18:36:43 +01:00
|
|
|
CURL *easy = m->easy_handle;
|
2023-04-26 12:38:22 +02:00
|
|
|
transfers--;
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_multi_remove_handle(multi, easy);
|
|
|
|
|
curl_easy_cleanup(easy);
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|
|
|
|
|
} while(m);
|
|
|
|
|
|
|
|
|
|
} while(transfers); /* as long as we have transfers going */
|
|
|
|
|
|
2025-10-31 17:36:27 +01:00
|
|
|
cleanup:
|
|
|
|
|
|
2025-10-31 18:36:43 +01:00
|
|
|
curl_multi_cleanup(multi);
|
2023-04-26 12:38:22 +02:00
|
|
|
|
2025-10-31 17:36:27 +01:00
|
|
|
if(out_download)
|
|
|
|
|
curlx_fclose(out_download);
|
2025-06-22 10:18:12 +02:00
|
|
|
if(out_push)
|
2025-09-14 15:34:18 +02:00
|
|
|
curlx_fclose(out_push);
|
2025-06-22 10:18:12 +02:00
|
|
|
|
2025-10-31 17:36:27 +01:00
|
|
|
curl_global_cleanup();
|
|
|
|
|
|
2025-12-16 13:40:02 +01:00
|
|
|
return result;
|
2023-04-26 12:38:22 +02:00
|
|
|
}
|