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/http/verb.hpp b/http/verb.hpp
new file mode 100644
index 0000000..33dd569
--- /dev/null
+++ b/http/verb.hpp
@@ -0,0 +1,69 @@
+#pragma once
+
+#include <boost/beast/http/verb.hpp>
+
+#include <optional>
+#include <string_view>
+
+enum class HttpVerb
+{
+ Delete = 0,
+ Get,
+ Head,
+ Options,
+ Patch,
+ Post,
+ Put,
+ Max,
+};
+
+inline std::optional<HttpVerb> httpVerbFromBoost(boost::beast::http::verb bv)
+{
+ switch (bv)
+ {
+ case boost::beast::http::verb::delete_:
+ return HttpVerb::Delete;
+ case boost::beast::http::verb::get:
+ return HttpVerb::Get;
+ case boost::beast::http::verb::head:
+ return HttpVerb::Head;
+ case boost::beast::http::verb::options:
+ return HttpVerb::Options;
+ case boost::beast::http::verb::patch:
+ return HttpVerb::Patch;
+ case boost::beast::http::verb::post:
+ return HttpVerb::Post;
+ case boost::beast::http::verb::put:
+ return HttpVerb::Put;
+ default:
+ return std::nullopt;
+ }
+
+ return std::nullopt;
+}
+
+inline std::string_view httpVerbToString(HttpVerb verb)
+{
+ switch (verb)
+ {
+ case HttpVerb::Delete:
+ return "DELETE";
+ case HttpVerb::Get:
+ return "GET";
+ case HttpVerb::Head:
+ return "HEAD";
+ case HttpVerb::Patch:
+ return "PATCH";
+ case HttpVerb::Post:
+ return "POST";
+ case HttpVerb::Put:
+ return "PUT";
+ case HttpVerb::Options:
+ return "OPTIONS";
+ case HttpVerb::Max:
+ return "";
+ }
+
+ // Should never reach here
+ return "";
+}