aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-10-04 17:41:06 -0700
committerGarrett D'Amore <garrett@damore.org>2025-10-04 17:57:56 -0700
commitcfcc004cff8f6e11c545070ed0e9ba0253227e44 (patch)
tree52e6c768ebb4de6bfffdfbb92c3cc025ffd90bb8 /src
parentd6eeff578cc8e2ada1a80f4d1ddaa098931f9a7d (diff)
downloadnng-cfcc004cff8f6e11c545070ed0e9ba0253227e44.tar.gz
nng-cfcc004cff8f6e11c545070ed0e9ba0253227e44.tar.bz2
nng-cfcc004cff8f6e11c545070ed0e9ba0253227e44.zip
tests: Add test for serving http static binary
Diffstat (limited to 'src')
-rw-r--r--src/supplemental/http/http_server_test.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/supplemental/http/http_server_test.c b/src/supplemental/http/http_server_test.c
index b55acd59..fdc38950 100644
--- a/src/supplemental/http/http_server_test.c
+++ b/src/supplemental/http/http_server_test.c
@@ -237,6 +237,53 @@ test_server_basic(void)
}
static void
+test_server_static_bin(void)
+{
+ struct server_test st;
+ char chunk[256];
+ const void *ptr;
+ nng_iov iov;
+ nng_http_handler *h;
+ static uint8_t data[3] = { 1, 0, 2 };
+
+ NUTS_PASS(nng_http_handler_alloc_static(
+ &h, "/data.bin", data, sizeof(data), NULL));
+
+ server_setup(&st, h);
+
+ NUTS_PASS(nng_http_set_uri(st.conn, "/data.bin", NULL));
+ nng_http_write_request(st.conn, st.aio);
+
+ nng_aio_wait(st.aio);
+ NUTS_PASS(nng_aio_result(st.aio));
+
+ nng_http_read_response(st.conn, st.aio);
+ nng_aio_wait(st.aio);
+ NUTS_PASS(nng_aio_result(st.aio));
+
+ NUTS_HTTP_STATUS(st.conn, NNG_HTTP_STATUS_OK);
+
+ ptr = nng_http_get_header(st.conn, "Content-Type");
+ NUTS_TRUE(ptr != NULL);
+ NUTS_TRUE(strcmp(ptr, "application/octet-stream") == 0);
+
+ ptr = nng_http_get_header(st.conn, "Content-Length");
+ NUTS_TRUE(ptr != NULL);
+ NUTS_TRUE(atoi(ptr) == (int) sizeof(data));
+
+ iov.iov_len = sizeof(data);
+ iov.iov_buf = chunk;
+ NUTS_PASS(nng_aio_set_iov(st.aio, 1, &iov));
+ nng_http_read_all(st.conn, st.aio);
+ nng_aio_wait(st.aio);
+ NUTS_PASS(nng_aio_result(st.aio));
+ NUTS_TRUE(nng_aio_count(st.aio) == sizeof(data));
+ NUTS_TRUE(memcmp(chunk, data, sizeof(data)) == 0);
+
+ server_free(&st);
+}
+
+static void
test_server_canonify(void)
{
struct server_test st;
@@ -1105,6 +1152,7 @@ test_serve_subdir_index(void)
NUTS_TESTS = {
{ "server basic", test_server_basic },
+ { "server static binary", test_server_static_bin },
{ "server canonify", test_server_canonify },
{ "server head", test_server_head },
{ "server 404", test_server_404 },