Boost beast
This commit is the beginings of attempting to transition away from
crow, and toward boost::beast. Unit tests are passing, and
implementation appears to be slightly faster than crow.
Change-Id: Ic8d946dc7a04f514c67b1098f181eee1ced69171
diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp
index b41439a..3fb0ce7 100644
--- a/redfish-core/include/node.hpp
+++ b/redfish-core/include/node.hpp
@@ -102,19 +102,19 @@
virtual void doPatch(crow::response& res, const crow::request& req,
const std::vector<std::string>& params) {
- res.code = static_cast<int>(HttpRespCode::METHOD_NOT_ALLOWED);
+ res.result(boost::beast::http::status::method_not_allowed);
res.end();
}
virtual void doPost(crow::response& res, const crow::request& req,
const std::vector<std::string>& params) {
- res.code = static_cast<int>(HttpRespCode::METHOD_NOT_ALLOWED);
+ res.result(boost::beast::http::status::method_not_allowed);
res.end();
}
virtual void doDelete(crow::response& res, const crow::request& req,
const std::vector<std::string>& params) {
- res.code = static_cast<int>(HttpRespCode::METHOD_NOT_ALLOWED);
+ res.result(boost::beast::http::status::method_not_allowed);
res.end();
}
@@ -127,14 +127,14 @@
auto ctx =
app.template get_context<crow::TokenAuthorization::Middleware>(req);
- if (!isMethodAllowedForUser(req.method, entityPrivileges,
+ if (!isMethodAllowedForUser(req.method(), entityPrivileges,
ctx.session->username)) {
- res.code = static_cast<int>(HttpRespCode::METHOD_NOT_ALLOWED);
+ res.result(boost::beast::http::status::method_not_allowed);
res.end();
return;
}
- switch (req.method) {
+ switch (req.method()) {
case "GET"_method:
doGet(res, req, params);
break;
@@ -152,7 +152,7 @@
break;
default:
- res.code = static_cast<int>(HttpRespCode::NOT_FOUND);
+ res.result(boost::beast::http::status::not_found);
res.end();
}
return;
diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp
index 1341f36..e98debb 100644
--- a/redfish-core/include/privileges.hpp
+++ b/redfish-core/include/privileges.hpp
@@ -157,8 +157,8 @@
std::bitset<MAX_PRIVILEGE_COUNT> privilegeBitset = 0;
};
-using OperationMap =
- boost::container::flat_map<crow::HTTPMethod, std::vector<Privileges>>;
+using OperationMap = boost::container::flat_map<boost::beast::http::verb,
+ std::vector<Privileges>>;
/**
* @brief Checks if given privileges allow to call an HTTP method
@@ -169,7 +169,7 @@
* @return True if method allowed, false otherwise
*
*/
-inline bool isMethodAllowedWithPrivileges(const crow::HTTPMethod method,
+inline bool isMethodAllowedWithPrivileges(const boost::beast::http::verb method,
const OperationMap& operationMap,
const Privileges& userPrivileges) {
const auto& it = operationMap.find(method);
@@ -199,7 +199,7 @@
* @return True if method allowed, false otherwise
*
*/
-inline bool isMethodAllowedForUser(const crow::HTTPMethod method,
+inline bool isMethodAllowedForUser(const boost::beast::http::verb method,
const OperationMap& operationMap,
const std::string& user) {
// TODO: load user privileges from configuration as soon as its available