xref: /openbmc/bmcweb/http/verb.hpp (revision a3b9eb98)
1 #pragma once
2 
3 #include <boost/beast/http/verb.hpp>
4 
5 #include <optional>
6 #include <string_view>
7 
8 enum class HttpVerb
9 {
10     Delete = 0,
11     Get,
12     Head,
13     Options,
14     Patch,
15     Post,
16     Put,
17     Max,
18 };
19 
20 static constexpr size_t maxVerbIndex = static_cast<size_t>(HttpVerb::Max) - 1U;
21 
httpVerbFromBoost(boost::beast::http::verb bv)22 inline std::optional<HttpVerb> httpVerbFromBoost(boost::beast::http::verb bv)
23 {
24     switch (bv)
25     {
26         case boost::beast::http::verb::delete_:
27             return HttpVerb::Delete;
28         case boost::beast::http::verb::get:
29             return HttpVerb::Get;
30         case boost::beast::http::verb::head:
31             return HttpVerb::Head;
32         case boost::beast::http::verb::options:
33             return HttpVerb::Options;
34         case boost::beast::http::verb::patch:
35             return HttpVerb::Patch;
36         case boost::beast::http::verb::post:
37             return HttpVerb::Post;
38         case boost::beast::http::verb::put:
39             return HttpVerb::Put;
40         default:
41             return std::nullopt;
42     }
43 }
44 
httpVerbToString(HttpVerb verb)45 inline std::string_view httpVerbToString(HttpVerb verb)
46 {
47     switch (verb)
48     {
49         case HttpVerb::Delete:
50             return "DELETE";
51         case HttpVerb::Get:
52             return "GET";
53         case HttpVerb::Head:
54             return "HEAD";
55         case HttpVerb::Patch:
56             return "PATCH";
57         case HttpVerb::Post:
58             return "POST";
59         case HttpVerb::Put:
60             return "PUT";
61         case HttpVerb::Options:
62             return "OPTIONS";
63         default:
64             return "";
65     }
66 
67     // Should never reach here
68     return "";
69 }
70