diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-22 12:32:15 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-22 12:32:15 -0800 |
| commit | a946d79e8d0eb3a47f75d6e1e98a28462c584d67 (patch) | |
| tree | dc848a251a9f483eccbae1d043e52136eabb473f | |
| parent | 2662596f105fc98ae1d2aa3b6137261bb351a8df (diff) | |
| download | nng-a946d79e8d0eb3a47f75d6e1e98a28462c584d67.tar.gz nng-a946d79e8d0eb3a47f75d6e1e98a28462c584d67.tar.bz2 nng-a946d79e8d0eb3a47f75d6e1e98a28462c584d67.zip | |
http: handler set tree no longer returns a value (API break)
| -rw-r--r-- | docs/man/nng_http_handler_set_tree.3http.adoc | 16 | ||||
| -rw-r--r-- | include/nng/supplemental/http/http.h | 4 | ||||
| -rw-r--r-- | src/supplemental/http/http_api.h | 4 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 10 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 18 | ||||
| -rw-r--r-- | src/supplemental/http/http_server_test.c | 12 |
6 files changed, 23 insertions, 41 deletions
diff --git a/docs/man/nng_http_handler_set_tree.3http.adoc b/docs/man/nng_http_handler_set_tree.3http.adoc index f0ecc4c9..3ee73de0 100644 --- a/docs/man/nng_http_handler_set_tree.3http.adoc +++ b/docs/man/nng_http_handler_set_tree.3http.adoc @@ -1,6 +1,6 @@ = nng_http_handler_set_tree(3http) -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2020 Dirac Research <robert.bielik@dirac.com> // @@ -20,9 +20,9 @@ nng_http_handler_set_tree - set HTTP handler to match trees #include <nng/nng.h> #include <nng/supplemental/http/http.h> -int nng_http_handler_set_tree(nng_http_handler *handler); +void nng_http_handler_set_tree(nng_http_handler *handler); -int nng_http_handler_set_tree_exclusive(nng_http_handler *handler); +void nng_http_handler_set_tree_exclusive(nng_http_handler *handler); ---- == DESCRIPTION @@ -48,16 +48,6 @@ generated when a more specific child does not exist. This can provide a better experience for users than the standard 404 error handling. -== RETURN VALUES - -This function returns 0 on success, and non-zero otherwise. - -== ERRORS - -[horizontal] -`NNG_ENOMEM`:: Insufficient free memory exists. -`NNG_ENOTSUP`:: No support for HTTP in the library. - == SEE ALSO [.text-left] diff --git a/include/nng/supplemental/http/http.h b/include/nng/supplemental/http/http.h index 4bcc6ec6..a25768e9 100644 --- a/include/nng/supplemental/http/http.h +++ b/include/nng/supplemental/http/http.h @@ -378,7 +378,7 @@ NNG_DECL int nng_http_handler_collect_body(nng_http_handler *, bool, size_t); // for a hierarchical tree, rather than just a single path, so it will be // called for all child paths supplied. By default the handler is only // called for an exact path match. -NNG_DECL int nng_http_handler_set_tree(nng_http_handler *); +NNG_DECL void nng_http_handler_set_tree(nng_http_handler *); // nng_http_handler_set_tree_exclusive indicates that the handler is being // registered for a heirarchical tree *exclusively*, rather than just a single @@ -386,7 +386,7 @@ NNG_DECL int nng_http_handler_set_tree(nng_http_handler *); // handler is only called for an exact path match. Exclusive means that any // other handler on a conflicting path will induce an address conflict error // when added to a server. -NNG_DECL int nng_http_handler_set_tree_exclusive(nng_http_handler *); +NNG_DECL void nng_http_handler_set_tree_exclusive(nng_http_handler *); // nng_http_handler_set_data is used to store additional data, along with // a possible clean up routine. (The clean up is a custom de-allocator and 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); |
