xref: /openbmc/bmcweb/http/verb.hpp (revision a3b9eb98)
12c9efc3cSEd Tanous #pragma once
22c9efc3cSEd Tanous 
32c9efc3cSEd Tanous #include <boost/beast/http/verb.hpp>
42c9efc3cSEd Tanous 
52c9efc3cSEd Tanous #include <optional>
62c9efc3cSEd Tanous #include <string_view>
72c9efc3cSEd Tanous 
82c9efc3cSEd Tanous enum class HttpVerb
92c9efc3cSEd Tanous {
102c9efc3cSEd Tanous     Delete = 0,
112c9efc3cSEd Tanous     Get,
122c9efc3cSEd Tanous     Head,
132c9efc3cSEd Tanous     Options,
142c9efc3cSEd Tanous     Patch,
152c9efc3cSEd Tanous     Post,
162c9efc3cSEd Tanous     Put,
172c9efc3cSEd Tanous     Max,
182c9efc3cSEd Tanous };
192c9efc3cSEd Tanous 
20c0bdf223SEdward Lee static constexpr size_t maxVerbIndex = static_cast<size_t>(HttpVerb::Max) - 1U;
21c0bdf223SEdward Lee 
httpVerbFromBoost(boost::beast::http::verb bv)222c9efc3cSEd Tanous inline std::optional<HttpVerb> httpVerbFromBoost(boost::beast::http::verb bv)
232c9efc3cSEd Tanous {
242c9efc3cSEd Tanous     switch (bv)
252c9efc3cSEd Tanous     {
262c9efc3cSEd Tanous         case boost::beast::http::verb::delete_:
272c9efc3cSEd Tanous             return HttpVerb::Delete;
282c9efc3cSEd Tanous         case boost::beast::http::verb::get:
292c9efc3cSEd Tanous             return HttpVerb::Get;
302c9efc3cSEd Tanous         case boost::beast::http::verb::head:
312c9efc3cSEd Tanous             return HttpVerb::Head;
322c9efc3cSEd Tanous         case boost::beast::http::verb::options:
332c9efc3cSEd Tanous             return HttpVerb::Options;
342c9efc3cSEd Tanous         case boost::beast::http::verb::patch:
352c9efc3cSEd Tanous             return HttpVerb::Patch;
362c9efc3cSEd Tanous         case boost::beast::http::verb::post:
372c9efc3cSEd Tanous             return HttpVerb::Post;
382c9efc3cSEd Tanous         case boost::beast::http::verb::put:
392c9efc3cSEd Tanous             return HttpVerb::Put;
402c9efc3cSEd Tanous         default:
412c9efc3cSEd Tanous             return std::nullopt;
422c9efc3cSEd Tanous     }
432c9efc3cSEd Tanous }
442c9efc3cSEd Tanous 
httpVerbToString(HttpVerb verb)452c9efc3cSEd Tanous inline std::string_view httpVerbToString(HttpVerb verb)
462c9efc3cSEd Tanous {
472c9efc3cSEd Tanous     switch (verb)
482c9efc3cSEd Tanous     {
492c9efc3cSEd Tanous         case HttpVerb::Delete:
502c9efc3cSEd Tanous             return "DELETE";
512c9efc3cSEd Tanous         case HttpVerb::Get:
522c9efc3cSEd Tanous             return "GET";
532c9efc3cSEd Tanous         case HttpVerb::Head:
542c9efc3cSEd Tanous             return "HEAD";
552c9efc3cSEd Tanous         case HttpVerb::Patch:
562c9efc3cSEd Tanous             return "PATCH";
572c9efc3cSEd Tanous         case HttpVerb::Post:
582c9efc3cSEd Tanous             return "POST";
592c9efc3cSEd Tanous         case HttpVerb::Put:
602c9efc3cSEd Tanous             return "PUT";
612c9efc3cSEd Tanous         case HttpVerb::Options:
622c9efc3cSEd Tanous             return "OPTIONS";
63*4da0490bSEd Tanous         default:
642c9efc3cSEd Tanous             return "";
652c9efc3cSEd Tanous     }
662c9efc3cSEd Tanous 
672c9efc3cSEd Tanous     // Should never reach here
682c9efc3cSEd Tanous     return "";
692c9efc3cSEd Tanous }
70