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