| #include "tlbmc/redfish/verb.h" |
| |
| #include <optional> |
| #include <string_view> |
| |
| #include "boost/beast/http/verb.hpp" //NOLINT |
| |
| namespace milotic_tlbmc { |
| |
| std::optional<HttpVerb> HttpVerbFromBoost(boost::beast::http::verb verb) { |
| switch (verb) { |
| case boost::beast::http::verb::delete_: |
| return HttpVerb::kDelete; |
| case boost::beast::http::verb::get: |
| return HttpVerb::kGet; |
| case boost::beast::http::verb::head: |
| return HttpVerb::kHead; |
| case boost::beast::http::verb::options: |
| return HttpVerb::kOptions; |
| case boost::beast::http::verb::patch: |
| return HttpVerb::kPatch; |
| case boost::beast::http::verb::post: |
| return HttpVerb::kPost; |
| case boost::beast::http::verb::put: |
| return HttpVerb::kPut; |
| default: |
| return std::nullopt; |
| } |
| return std::nullopt; |
| } |
| |
| std::string_view HttpVerbToString(HttpVerb verb) { |
| switch (verb) { |
| case HttpVerb::kDelete: |
| return "DELETE"; |
| case HttpVerb::kGet: |
| return "GET"; |
| case HttpVerb::kHead: |
| return "HEAD"; |
| case HttpVerb::kPatch: |
| return "PATCH"; |
| case HttpVerb::kPost: |
| return "POST"; |
| case HttpVerb::kPut: |
| return "PUT"; |
| case HttpVerb::kOptions: |
| return "OPTIONS"; |
| case HttpVerb::kMax: |
| return ""; |
| } |
| // Should never reach here |
| return ""; |
| } |
| |
| std::string_view BoostVerbToString(boost::beast::http::verb v) { |
| std::optional<HttpVerb> verb = HttpVerbFromBoost(v); |
| if (!verb) { |
| return ""; |
| } |
| return HttpVerbToString(*verb); |
| } |
| |
| } // namespace milotic_tlbmc |