libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 7ba69b8c8bf341b923c49e38b40bc79d3206a668
parent f9a0f497d8537fecc71613fb590119b2c8dccf07
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Mon, 17 Aug 2026 18:41:53 +0200

tests/client_server: implemented testing with larger payloads

Diffstat:
Msrc/tests/client_server/libtest.c | 24++++++++++++++++++++++++
Msrc/tests/client_server/libtest.h | 17+++++++++++++++++
Msrc/tests/client_server/test_client_server.c | 30++++++++++++++++++++++++++++++
Msrc/tests/client_server/test_http2.c | 33+++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/src/tests/client_server/libtest.c b/src/tests/client_server/libtest.c @@ -793,3 +793,27 @@ MHDT_load_pem (const char *name) buf[(size_t)s.st_size] = 0; return buf; } + + +void +MHDT_fill_text_data (char *buf, + size_t buf_size) +{ + size_t i; + + if (0u == buf_size) + return; + + for (i = 0u; i < buf_size - 1; ++i) + { + const size_t pos = i + 26u; + if (0u == pos % 17u) + buf[i] = ' '; + else if (0u == pos % 101u) + buf[i] = ','; + else + buf[i] = (char)(unsigned char) + ('a' + (pos ^ (pos << 3u)) % ('z' - 'a' + 1u)); + } + buf[buf_size - 1] = 0; +} diff --git a/src/tests/client_server/libtest.h b/src/tests/client_server/libtest.h @@ -192,6 +192,23 @@ MHDT_load_pem (const char *name); /** + * Fill the buffer with the text-like data and zero-terminate it. + * + * The generated data is position-dependent, therefore any shift, repetition + * or loss of the transferred data is detected by the content check. + * The data has spaces, so it could be split to "words" by the chunked + * response callback. + * + * @param[out] buf the buffer to fill + * @param buf_size the size of the @a buf buffer, including the space for + * the terminating zero; must be non-zero + */ +void +MHDT_fill_text_data (char *buf, + size_t buf_size); + + +/** * Run request against the root URL of the * hostname given in @a cls. * diff --git a/src/tests/client_server/test_client_server.c b/src/tests/client_server/test_client_server.c @@ -203,6 +203,7 @@ main (int argc, char *argv[]) .label = "END" } }; + static char medium_text[20000]; struct MHDT_Phase phases[] = { { .label = "simple get", @@ -221,6 +222,32 @@ main (int argc, char *argv[]) .timeout_ms = 2500, }, { + /* The body does not fit a single send() buffer, so it is transferred + by several iterations */ + .label = "medium body get, buffer response", + .server_cb = &MHDT_server_reply_text, + .server_cb_cls = medium_text, + .client_cb = &MHDT_client_get_root, + .client_cb_cls = medium_text, + .timeout_ms = 5000, + }, + { + .label = "medium body get, file response", + .server_cb = &MHDT_server_reply_file, + .server_cb_cls = medium_text, + .client_cb = &MHDT_client_get_root, + .client_cb_cls = medium_text, + .timeout_ms = 5000, + }, + { + .label = "medium body get, callback response", + .server_cb = &MHDT_server_reply_chunked_text, + .server_cb_cls = medium_text, + .client_cb = &MHDT_client_get_root, + .client_cb_cls = medium_text, + .timeout_ms = 5000, + }, + { .label = "client PUT with content-length", .server_cb = &MHDT_server_reply_check_upload, .server_cb_cls = (void *)"simple-upload-value", @@ -315,6 +342,9 @@ main (int argc, char *argv[]) (void)argc; /* Unused. Silence compiler warning. */ (void)argv; /* Unused. Silence compiler warning. */ + MHDT_fill_text_data (medium_text, + sizeof(medium_text)); + for (i = 0; NULL != configs[i].server_setup; i++) { int ret; diff --git a/src/tests/client_server/test_http2.c b/src/tests/client_server/test_http2.c @@ -168,6 +168,7 @@ main (int argc, char *argv[]) .label = "END" } }; + static char medium_text[20000]; struct MHDT_Phase phases[] = { { .label = "simple get", @@ -187,6 +188,26 @@ main (int argc, char *argv[]) .timeout_ms = 2500, .http_version = 2, }, + { + /* The body is larger than the default HTTP/2 max frame size, + so it is sent by several DATA frames */ + .label = "medium body get, buffer response", + .server_cb = &MHDT_server_reply_text, + .server_cb_cls = medium_text, + .client_cb = &MHDT_client_get_root, + .client_cb_cls = medium_text, + .timeout_ms = 5000, + .http_version = 2, + }, + { + .label = "medium body get, file response", + .server_cb = &MHDT_server_reply_file, + .server_cb_cls = medium_text, + .client_cb = &MHDT_client_get_root, + .client_cb_cls = medium_text, + .timeout_ms = 5000, + .http_version = 2, + }, #if 0 { .label = "client PUT with content-length", @@ -285,6 +306,15 @@ main (int argc, char *argv[]) .timeout_ms = 2500, .http_version = 2, }, + { + .label = "medium body get, callback response", + .server_cb = &MHDT_server_reply_chunked_text, + .server_cb_cls = medium_text, + .client_cb = &MHDT_client_get_root, + .client_cb_cls = medium_text, + .timeout_ms = 5000, + .http_version = 2, + }, #endif // TODO: chunked download { @@ -296,6 +326,9 @@ main (int argc, char *argv[]) (void)argc; /* Unused. Silence compiler warning. */ (void)argv; /* Unused. Silence compiler warning. */ + MHDT_fill_text_data (medium_text, + sizeof(medium_text)); + for (i = 0; NULL != configs[i].server_setup; i++) { int ret;