blob: 92bc360974531feab143b904f020814c56c66bf5 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous2c9efc32022-07-31 22:08:26 -07003#pragma once
4
5#include <boost/beast/http/verb.hpp>
6
7#include <optional>
8#include <string_view>
9
10enum class HttpVerb
11{
12 Delete = 0,
13 Get,
14 Head,
15 Options,
16 Patch,
17 Post,
18 Put,
19 Max,
20};
21
Edward Leec0bdf222022-11-11 23:38:17 +000022static constexpr size_t maxVerbIndex = static_cast<size_t>(HttpVerb::Max) - 1U;
23
Ed Tanous2c9efc32022-07-31 22:08:26 -070024inline 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 }
Ed Tanous2c9efc32022-07-31 22:08:26 -070045}
46
47inline 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";
Ed Tanous4da04902024-03-19 11:32:44 -070065 default:
Ed Tanous2c9efc32022-07-31 22:08:26 -070066 return "";
67 }
68
69 // Should never reach here
70 return "";
71}