diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-12-22 12:27:49 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-12-22 12:27:49 -0800 |
| commit | 2662596f105fc98ae1d2aa3b6137261bb351a8df (patch) | |
| tree | 0c23c11eab6229cd7481a6294e1b447a6f309de7 | |
| parent | 10f6fc5141a15e368dac813a38942cb66d5ddef4 (diff) | |
| download | nng-2662596f105fc98ae1d2aa3b6137261bb351a8df.tar.gz nng-2662596f105fc98ae1d2aa3b6137261bb351a8df.tar.bz2 nng-2662596f105fc98ae1d2aa3b6137261bb351a8df.zip | |
HTTP: nng_http_handler_set_method no longer fails
| -rw-r--r-- | docs/man/nng_http_handler_set_method.3http.adoc | 15 | ||||
| -rw-r--r-- | docs/ref/migrate/nng1.md | 10 | ||||
| -rw-r--r-- | include/nng/supplemental/http/http.h | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_api.h | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_public.c | 5 | ||||
| -rw-r--r-- | src/supplemental/http/http_server.c | 16 | ||||
| -rw-r--r-- | src/supplemental/http/http_server_test.c | 9 |
7 files changed, 21 insertions, 38 deletions
diff --git a/docs/man/nng_http_handler_set_method.3http.adoc b/docs/man/nng_http_handler_set_method.3http.adoc index f79f0faf..17c4481d 100644 --- a/docs/man/nng_http_handler_set_method.3http.adoc +++ b/docs/man/nng_http_handler_set_method.3http.adoc @@ -20,7 +20,7 @@ nng_http_handler_set_method - set HTTP handler method #include <nng/nng.h> #include <nng/supplemental/http/http.h> -int nng_http_handler_set_method(nng_http_handler *handler, const char *method); +void nng_http_handler_set_method(nng_http_handler *handler, const char *method); ---- == DESCRIPTION @@ -36,22 +36,11 @@ NOTE: The server will automatically call "GET" handlers if the client sends a "HEAD" request, and will suppress HTTP body data in the responses sent for such requests. -NOTE: No validation of the _method_ is performed, but HTTP specifications -insist that the actual method sent over the wire be capitalized. +NOTE: If _method_ is longer than 32-bytes, it may be truncated silently. The handler may always examine the actual method used using the xref:nng_http_req_get_method.3http.adoc[`nng_http_req_get_method()`] function. -== 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/docs/ref/migrate/nng1.md b/docs/ref/migrate/nng1.md index 544f15b6..8035f854 100644 --- a/docs/ref/migrate/nng1.md +++ b/docs/ref/migrate/nng1.md @@ -229,11 +229,13 @@ they may be silently truncated to the limit: - HTTP Method names are limited to 32 bytes (the longest IANA registered method is currently 18 bytes, used for WebDAV.) - The fixed part of URI pathnames used with HTTP handlers is limited to 1024 bytes. -The following API changes are present: +The following API calls have changed so that they are `void` returns, and cannot fail. +They may silently truncate data, and the handler methods may not have any effect if the handler is already in use. -- [`nng_http_req_set_method`] no longer returns a value, and cannot fail. -- [`nng_http_res_set_status`] no longer returns a value, and cannot fail. -- [`nng_http_handler_set_host`] no longer returns a value and cannot fail. +- [`nng_http_req_set_method`] +- [`nng_http_res_set_status`] +- [`nng_http_handler_set_host`] +- [`nng_http_handler_set_method`] ## Security Descriptors (Windows Only) diff --git a/include/nng/supplemental/http/http.h b/include/nng/supplemental/http/http.h index 729e25ad..4bcc6ec6 100644 --- a/include/nng/supplemental/http/http.h +++ b/include/nng/supplemental/http/http.h @@ -355,7 +355,7 @@ NNG_DECL int nng_http_handler_alloc_directory( // called for. By default this is GET. If NULL is supplied for the // method, then the handler is executed regardless of method, and must // inspect the method itself. -NNG_DECL int nng_http_handler_set_method(nng_http_handler *, const char *); +NNG_DECL void nng_http_handler_set_method(nng_http_handler *, const char *); // nng_http_handler_set_host sets the Host: that the handler will be // called for (to allow for virtual hosts). If the value is NULL (the diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index d759e27b..0748b1f9 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -332,7 +332,7 @@ extern void nni_http_handler_set_host(nni_http_handler *, const char *); // is obligated to inspect the method. (Note: the passed method must be // in upper case and should come from a statically allocated string; the // server does not make its own copy.) -extern int nni_http_handler_set_method(nni_http_handler *, const char *); +extern void nni_http_handler_set_method(nni_http_handler *, const char *); // nni_http_handler_set_data sets an opaque data element on the handler, // which will be available to the callback via nni_http_handler_get_data. diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index a60743fd..58550a3f 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -583,15 +583,14 @@ nng_http_handler_alloc_static(nng_http_handler **hp, const char *uri, #endif } -int +void nng_http_handler_set_method(nng_http_handler *h, const char *meth) { #ifdef NNG_SUPP_HTTP - return (nni_http_handler_set_method(h, meth)); + nni_http_handler_set_method(h, meth); #else NNI_ARG_UNUSED(h); NNI_ARG_UNUSED(meth); - return (NNG_ENOTSUP); #endif } diff --git a/src/supplemental/http/http_server.c b/src/supplemental/http/http_server.c index e9c8bea3..6a594158 100644 --- a/src/supplemental/http/http_server.c +++ b/src/supplemental/http/http_server.c @@ -236,20 +236,14 @@ nni_http_handler_set_host(nni_http_handler *h, const char *host) (void) snprintf(h->host, sizeof(h->host), "%s", host); } -int +void nni_http_handler_set_method(nni_http_handler *h, const char *method) { - if (nni_atomic_get_bool(&h->busy) != 0) { - return (NNG_EBUSY); - } + NNI_ASSERT(!nni_atomic_get_bool(&h->busy)); if (method == NULL) { method = ""; } - if (strlen(method) >= sizeof(h->method)) { - return (NNG_EINVAL); - } (void) snprintf(h->method, sizeof(h->method), "%s", method); - return (0); } static nni_list http_servers = @@ -1757,9 +1751,9 @@ nni_http_handler_init_redirect(nni_http_handler **hpp, const char *uri, return (rv); } - if (((rv = nni_http_handler_set_method(h, NULL)) != 0) || - ((rv = nni_http_handler_set_data(h, hr, http_redirect_free)) != - 0)) { + nni_http_handler_set_method(h, NULL); + + if ((rv = nni_http_handler_set_data(h, hr, http_redirect_free)) != 0) { http_redirect_free(hr); 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 f29fa52b..e1d13ad2 100644 --- a/src/supplemental/http/http_server_test.c +++ b/src/supplemental/http/http_server_test.c @@ -346,10 +346,9 @@ test_server_method_too_long(void) NUTS_PASS(nng_http_handler_alloc_static( &h, "/home.html", doc1, strlen(doc1), "text/html")); - NUTS_FAIL(nng_http_handler_set_method(h, - "THISMETHODISFARFARTOOLONGTOBEVALIDASAMETHODASITISLONGER" - "THANTHIRTYTWOBYTES"), - NNG_EINVAL); + nng_http_handler_set_method(h, + "THISMETHODISFARFARTOOLONGTOBEVALIDASAMETHODASITISLONGER" + "THANTHIRTYTWOBYTES"); } void @@ -393,7 +392,7 @@ test_server_post_handler(void) void *data; NUTS_PASS(nng_http_handler_alloc(&h, "/post", httpecho)); - NUTS_PASS(nng_http_handler_set_method(h, "POST")); + nng_http_handler_set_method(h, "POST"); server_setup(&st, h); |
