aboutsummaryrefslogtreecommitdiff
path: root/src/supplemental/http/http_server_test.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-12-22 11:17:24 -0800
committerGarrett D'Amore <garrett@damore.org>2024-12-22 11:17:24 -0800
commit6800bdd8b9e3fd4488bab56cd9fb12206d0631f6 (patch)
tree2b4134dd1a20815d8eb055d963119658c1b49877 /src/supplemental/http/http_server_test.c
parente390aeca2d536bf023ee1386b956dca017539446 (diff)
downloadnng-6800bdd8b9e3fd4488bab56cd9fb12206d0631f6.tar.gz
nng-6800bdd8b9e3fd4488bab56cd9fb12206d0631f6.tar.bz2
nng-6800bdd8b9e3fd4488bab56cd9fb12206d0631f6.zip
http handler: avoid method allocation
We limit HTTP method lengths to 32.. there are no currently defined HTTP methods that need more than 19 bytes (including trailing zero.) Generally most servers will not have vast numbers of handlers, so the cost of allocating some storage up front to avoid the dynamic allocation is worth while.
Diffstat (limited to 'src/supplemental/http/http_server_test.c')
-rw-r--r--src/supplemental/http/http_server_test.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/supplemental/http/http_server_test.c b/src/supplemental/http/http_server_test.c
index 2d1e4b28..2ed04c4d 100644
--- a/src/supplemental/http/http_server_test.c
+++ b/src/supplemental/http/http_server_test.c
@@ -339,6 +339,20 @@ test_server_missing_host(void)
}
void
+test_server_method_too_long(void)
+{
+ nng_http_handler *h;
+
+ 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);
+}
+
+void
test_server_wrong_method(void)
{
struct server_test st;
@@ -898,6 +912,7 @@ NUTS_TESTS = {
{ "server bad version", test_server_bad_version },
{ "server missing host", test_server_missing_host },
{ "server wrong method", test_server_wrong_method },
+ { "server method too long", test_server_method_too_long },
{ "server post handler", test_server_post_handler },
{ "server get redirect", test_server_get_redirect },
{ "server tree redirect", test_server_tree_redirect },