Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http test: test HEAD method in server #2078

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/supplemental/http/http_server_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,53 @@ test_server_basic(void)
server_free(&st);
}

static void
test_server_head(void)
{
struct server_test st;
void *ptr;
size_t size;
nng_http_handler *h;

NUTS_PASS(nng_http_handler_alloc_static(
&h, "/home.html", doc1, strlen(doc1), "text/html"));

server_setup(&st, h);

NUTS_PASS(nng_http_set_uri(st.conn, "/home.html", NULL));
nng_http_set_method(st.conn, "HEAD");
nng_http_transact(st.conn, st.aio);

nng_aio_wait(st.aio);
NUTS_PASS(nng_aio_result(st.aio));

NUTS_TRUE(nng_http_get_status(st.conn) == NNG_HTTP_STATUS_OK);

ptr = (char *) nng_http_get_header(st.conn, "Content-Length");
NUTS_TRUE(ptr != NULL);
NUTS_TRUE(atoi(ptr) == (int) strlen(doc1));
NUTS_TRUE(nng_http_get_status(st.conn) == NNG_HTTP_STATUS_OK);

nng_http_get_body(st.conn, &ptr, &size);
NUTS_TRUE(size == 0);
NUTS_TRUE(ptr == NULL);

nng_http_reset(st.conn);
nng_http_set_uri(st.conn, "/home.html", NULL);
nng_http_set_method(st.conn, "GET");
nng_http_transact(st.conn, st.aio);

nng_aio_wait(st.aio);
NUTS_PASS(nng_aio_result(st.aio));
NUTS_TRUE(nng_http_get_status(st.conn) == NNG_HTTP_STATUS_OK);
nng_http_get_body(st.conn, &ptr, &size);

NUTS_TRUE(size == strlen(doc1));
NUTS_TRUE(memcmp(ptr, doc1, strlen(doc1)) == 0);

server_free(&st);
}

static void
test_server_404(void)
{
Expand Down Expand Up @@ -886,6 +933,7 @@ test_serve_subdir_index(void)

NUTS_TESTS = {
{ "server basic", test_server_basic },
{ "server head", test_server_head },
{ "server 404", test_server_404 },
{ "server bad version", test_server_bad_version },
{ "server missing host", test_server_missing_host },
Expand Down
Loading