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