Simplify router
Now that we only support string types in the router we no longer need to
build a "Tag" to be used for constructing argument types. Now, we can
just track the number of arguments, which simplifies the code
significantly, and removes the need to convert to and from the tag to
parameter counts.
This in turn deletes a lot of code in the router, removing the need for
tracking tag types.
Tested: Redfish service validator passes. Unit tests pass.
Change-Id: Ide1d665dc1984552681e8c05952b38073d5e32dd
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/test/http/router_test.cpp b/test/http/router_test.cpp
index edd9054..f233317 100644
--- a/test/http/router_test.cpp
+++ b/test/http/router_test.cpp
@@ -62,6 +62,41 @@
EXPECT_NE(router.findRoute(patchReq).route.rule, nullptr);
}
+TEST(Router, OverlapingRoutes)
+{
+ // Callback handler that does nothing
+ auto fooCallback = [](const Request&,
+ const std::shared_ptr<bmcweb::AsyncResp>&) {
+ EXPECT_FALSE(true);
+ };
+ bool barCalled = false;
+ auto foobarCallback =
+ [&barCalled](const Request&, const std::shared_ptr<bmcweb::AsyncResp>&,
+ const std::string& bar) {
+ barCalled = true;
+ EXPECT_EQ(bar, "bar");
+ };
+
+ Router router;
+ std::error_code ec;
+
+ router.newRuleTagged<getParameterTag("/foo/<str>")>("/foo/<str>")(
+ foobarCallback);
+ router.newRuleTagged<getParameterTag("/foo")>("/foo")(fooCallback);
+ router.validate();
+ {
+ constexpr std::string_view url = "/foo/bar";
+
+ Request req{{boost::beast::http::verb::get, url, 11}, ec};
+
+ std::shared_ptr<bmcweb::AsyncResp> asyncResp =
+ std::make_shared<bmcweb::AsyncResp>();
+
+ router.handle(req, asyncResp);
+ }
+ EXPECT_TRUE(barCalled);
+}
+
TEST(Router, 404)
{
bool notFoundCalled = false;