Make router take up less space for verbs
As is, the router designates routes for every possible boost verb, of
which there are 31. In bmcweb, we only make use of 6 of those verbs, so
that ends up being quite a bit of wasted space and cache non-locality.
This commit invents a new enum class for declaring a subset of boost
verbs that we support, and a mapping between bmcweb verbs and boost
verbs.
Then it walks through and updates the router to support converting one
to another.
Tested:
Unit Tested
Redfish Service Validator performed on future commit
Signed-off-by: Ed Tanous <edtanous@google.com>
Signed-off-by: Edward Lee <edwarddl@google.com>
Change-Id: I3c89e896c632a5d4134dbd08a30b313c12a60de6
diff --git a/test/http/verb_test.cpp b/test/http/verb_test.cpp
new file mode 100644
index 0000000..76dd8d0
--- /dev/null
+++ b/test/http/verb_test.cpp
@@ -0,0 +1,56 @@
+#include "verb.hpp"
+
+#include <boost/beast/http/verb.hpp>
+
+#include <map>
+#include <optional>
+#include <string_view>
+
+#include <gtest/gtest.h> // IWYU pragma: keep
+
+using BoostVerb = boost::beast::http::verb;
+
+TEST(BoostToHttpVerb, ValidCase)
+{
+ std::map<HttpVerb, BoostVerb> verbMap = {
+ {HttpVerb::Delete, BoostVerb::delete_},
+ {HttpVerb::Get, BoostVerb::get},
+ {HttpVerb::Head, BoostVerb::head},
+ {HttpVerb::Options, BoostVerb::options},
+ {HttpVerb::Patch, BoostVerb::patch},
+ {HttpVerb::Post, BoostVerb::post},
+ {HttpVerb::Put, BoostVerb::put},
+ };
+
+ for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
+ ++verbIndex)
+ {
+ HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
+ std::optional<HttpVerb> verb = httpVerbFromBoost(verbMap[httpVerb]);
+ ASSERT_TRUE(verb.has_value());
+ EXPECT_EQ(*verb, httpVerb);
+ }
+}
+
+TEST(BoostToHttpVerbTest, InvalidCase)
+{
+ std::optional<HttpVerb> verb = httpVerbFromBoost(BoostVerb::unknown);
+ EXPECT_FALSE(verb.has_value());
+}
+
+TEST(HttpVerbToStringTest, ValidCase)
+{
+ std::map<HttpVerb, std::string_view> verbMap = {
+ {HttpVerb::Delete, "DELETE"}, {HttpVerb::Get, "GET"},
+ {HttpVerb::Head, "HEAD"}, {HttpVerb::Options, "OPTIONS"},
+ {HttpVerb::Patch, "PATCH"}, {HttpVerb::Post, "POST"},
+ {HttpVerb::Put, "PUT"},
+ };
+
+ for (int verbIndex = 0; verbIndex < static_cast<int>(HttpVerb::Max);
+ ++verbIndex)
+ {
+ HttpVerb httpVerb = static_cast<HttpVerb>(verbIndex);
+ EXPECT_EQ(httpVerbToString(httpVerb), verbMap[httpVerb]);
+ }
+}
\ No newline at end of file