aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-22 12:32:15 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-22 12:32:15 -0800
commita946d79e8d0eb3a47f75d6e1e98a28462c584d67 (patch)
treedc848a251a9f483eccbae1d043e52136eabb473f /src
parent2662596f105fc98ae1d2aa3b6137261bb351a8df (diff)
downloadnng-a946d79e8d0eb3a47f75d6e1e98a28462c584d67.tar.gz
nng-a946d79e8d0eb3a47f75d6e1e98a28462c584d67.tar.bz2
nng-a946d79e8d0eb3a47f75d6e1e98a28462c584d67.zip
http: handler set tree no longer returns a value (API break)
Diffstat (limited to 'src')
-rw-r--r--src/supplemental/http/http_api.h4
-rw-r--r--src/supplemental/http/http_public.c10
-rw-r--r--src/supplemental/http/http_server.c18
-rw-r--r--src/supplemental/http/http_server_test.c12
4 files changed, 18 insertions, 26 deletions
diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h
index 0748b1f9..47e46b53 100644
--- a/src/supplemental/http/http_api.h
+++ b/src/supplemental/http/http_api.h
@@ -304,14 +304,14 @@ extern void nni_http_handler_collect_body(nni_http_handler *, bool, size_t);
// nni_http_handler_set_tree marks the handler as servicing the entire
// tree (e.g. a directory), rather than just a leaf node. The handler
// will probably need to inspect the URL of the request.
-extern int nni_http_handler_set_tree(nni_http_handler *);
+extern void nni_http_handler_set_tree(nni_http_handler *);
// nni_http_handler_set_tree_exclusive marks the handler as servicing the
// entire tree (e.g. a directory) exclusively, rather than just a leaf node.
// When servicing a tree exclusively, other handlers sharing parts of the uri
// will induce an address conflict when adding them to a server. The handler
// will probably need to inspect the URL of the request.
-extern int nni_http_handler_set_tree_exclusive(nni_http_handler *);
+extern void nni_http_handler_set_tree_exclusive(nni_http_handler *);
// nni_http_handler_set_host limits the handler to only being called for
// the given Host: field. This can be used to set up multiple virtual
diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c
index 58550a3f..f85eca64 100644
--- a/src/supplemental/http/http_public.c
+++ b/src/supplemental/http/http_public.c
@@ -619,25 +619,23 @@ nng_http_handler_set_host(nng_http_handler *h, const char *host)
#endif
}
-int
+void
nng_http_handler_set_tree(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
- return (nni_http_handler_set_tree(h));
+ nni_http_handler_set_tree(h);
#else
NNI_ARG_UNUSED(h);
- return (NNG_ENOTSUP);
#endif
}
-int
+void
nng_http_handler_set_tree_exclusive(nng_http_handler *h)
{
#ifdef NNG_SUPP_HTTP
- return (nni_http_handler_set_tree_exclusive(h));
+ nni_http_handler_set_tree_exclusive(h);
#else
NNI_ARG_UNUSED(h);
- return (NNG_ENOTSUP);
#endif
}
diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c
index 6a594158..38204ca5 100644
--- a/src/supplemental/http/http_server.c
+++ b/src/supplemental/http/http_server.c
@@ -180,26 +180,20 @@ nni_http_handler_get_uri(nni_http_handler *h)
return (h->uri);
}
-int
+void
nni_http_handler_set_tree(nni_http_handler *h)
{
- if (nni_atomic_get_bool(&h->busy) != 0) {
- return (NNG_EBUSY);
- }
+ NNI_ASSERT(!nni_atomic_get_bool(&h->busy));
h->tree = true;
h->tree_exclusive = false;
- return (0);
}
-int
+void
nni_http_handler_set_tree_exclusive(nni_http_handler *h)
{
- if (nni_atomic_get_bool(&h->busy) != 0) {
- return (NNG_EBUSY);
- }
+ NNI_ASSERT(!nni_atomic_get_bool(&h->busy));
h->tree = true;
h->tree_exclusive = true;
- return (0);
}
void
@@ -1629,9 +1623,9 @@ nni_http_handler_init_directory(
}
// We don't permit a body for getting a file.
nni_http_handler_collect_body(h, true, 0);
+ nni_http_handler_set_tree_exclusive(h);
- if (((rv = nni_http_handler_set_tree_exclusive(h)) != 0) ||
- ((rv = nni_http_handler_set_data(h, hf, http_file_free)) != 0)) {
+ if ((rv = nni_http_handler_set_data(h, hf, http_file_free)) != 0) {
http_file_free(hf);
nni_http_handler_fini(h);
return (rv);
diff --git a/src/supplemental/http/http_server_test.c b/src/supplemental/http/http_server_test.c
index e1d13ad2..0f6227f2 100644
--- a/src/supplemental/http/http_server_test.c
+++ b/src/supplemental/http/http_server_test.c
@@ -464,7 +464,7 @@ test_server_tree_redirect(void)
// We'll use a 303 to ensure codes carry thru
NUTS_PASS(nng_http_handler_alloc_redirect(
&h, "/here", 303, "http://127.0.0.1/there"));
- NUTS_PASS(nng_http_handler_set_tree(h));
+ nng_http_handler_set_tree(h);
server_setup(&st, h);
NUTS_PASS(nng_http_req_set_uri(st.req, "/here/i/go/again"));
@@ -521,7 +521,7 @@ test_server_post_echo_tree(void)
NUTS_PASS(nng_http_handler_alloc(&h, "/", httpecho));
nng_http_handler_set_method(h, "POST");
- NUTS_PASS(nng_http_handler_set_tree(h));
+ nng_http_handler_set_tree(h);
server_setup(&st, h);
@@ -587,20 +587,20 @@ test_server_multiple_trees(void)
NUTS_PASS(nni_file_put(file2, doc2, strlen(doc2)));
NUTS_PASS(nng_http_handler_alloc_directory(&h, "/", workdir));
- NUTS_PASS(nng_http_handler_set_tree(h));
+ nng_http_handler_set_tree(h);
server_setup(&st, h);
NUTS_PASS(nng_http_handler_alloc_directory(&h, "/", workdir));
- NUTS_PASS(nng_http_handler_set_tree(h));
+ nng_http_handler_set_tree(h);
NUTS_FAIL(nng_http_server_add_handler(st.s, h), NNG_EADDRINUSE);
nng_http_handler_free(h);
NUTS_PASS(nng_http_handler_alloc_directory(&h, "/subdir", workdir2));
- NUTS_PASS(nng_http_handler_set_tree(h));
+ nng_http_handler_set_tree(h);
NUTS_PASS(nng_http_server_add_handler(st.s, h));
NUTS_PASS(nng_http_handler_alloc_directory(&h, "/subdir", workdir2));
- NUTS_PASS(nng_http_handler_set_tree(h));
+ nng_http_handler_set_tree(h);
NUTS_FAIL(nng_http_server_add_handler(st.s, h), NNG_EADDRINUSE);
nng_http_handler_free(h);