Skip to content

Commit dfc02bd

Browse files
jukkarkartben
authored andcommitted
net: http: server: The detail length of wildcard detail was wrong
The path length of the detail resource was not set properly. Signed-off-by: Jukka Rissanen <[email protected]> (cherry picked from commit 33cf7dc)
1 parent 2793658 commit dfc02bd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

subsys/net/lib/http/http_server_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ struct http_resource_detail *get_resource_detail(const struct http_service_desc
762762

763763
ret = fnmatch(resource->resource, path, (FNM_PATHNAME | FNM_LEADING_DIR));
764764
if (ret == 0) {
765-
*path_len = strlen(resource->resource);
765+
*path_len = path_len_without_query(path);
766766
return resource->detail;
767767
}
768768
}

tests/net/lib/http_server/common/src/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ HTTP_RESOURCE_DEFINE(resource_6, service_D, "/fo*", RES(1));
7777
HTTP_RESOURCE_DEFINE(resource_7, service_D, "/f[ob]o3.html", RES(1));
7878
HTTP_RESOURCE_DEFINE(resource_8, service_D, "/fb?3.htm", RES(0));
7979
HTTP_RESOURCE_DEFINE(resource_9, service_D, "/f*4.html", RES(3));
80+
HTTP_RESOURCE_DEFINE(resource_11, service_D, "/foo/*", RES(3));
81+
HTTP_RESOURCE_DEFINE(resource_12, service_D, "/foo/b?r", RES(3));
8082

8183
/* Default resource in case of no match */
8284
static uint16_t service_E_port = 8080;
@@ -373,6 +375,25 @@ ZTEST(http_service, test_HTTP_RESOURCE_WILDCARD)
373375
res = CHECK_PATH(service_A, "/fbo3.htm", &len);
374376
zassert_is_null(res, "Resource found");
375377
zassert_equal(len, 0, "Length set");
378+
379+
res = CHECK_PATH(service_D, "/foo/bar", &len);
380+
zassert_not_null(res, "Resource not found");
381+
zassert_true(len == (sizeof("/foo/bar") - 1), "Length not set correctly");
382+
zassert_equal(res, RES(3), "Resource mismatch");
383+
384+
res = CHECK_PATH(service_D, "/foo/bar?param=value", &len);
385+
zassert_not_null(res, "Resource not found");
386+
zassert_true(len == (sizeof("/foo/bar") - 1), "Length not set correctly");
387+
zassert_equal(res, RES(3), "Resource mismatch");
388+
389+
res = CHECK_PATH(service_D, "/bar?foo=value", &len);
390+
zassert_is_null(res, "Resource found");
391+
zassert_equal(len, 0, "Length set");
392+
393+
res = CHECK_PATH(service_D, "/foo/bar?param=value", &len);
394+
zassert_not_null(res, "Resource not found");
395+
zassert_true(len == (sizeof("/foo/bar") - 1), "Length not set correctly");
396+
zassert_equal(res, RES(3), "Resource mismatch");
376397
}
377398

378399
ZTEST(http_service, test_HTTP_RESOURCE_DEFAULT)

0 commit comments

Comments
 (0)