| Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 | 
|  | 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors | 
| Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 3 | #pragma once | 
|  | 4 |  | 
|  | 5 | #include <boost/beast/http/verb.hpp> | 
|  | 6 |  | 
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 7 | #include <cstddef> | 
| Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 8 | #include <optional> | 
| Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | // boost/beast/http/verb for whatever reason requires this? | 
|  | 10 | // NOLINTNEXTLINE(misc-include-cleaner) | 
|  | 11 | #include <ostream> | 
| Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 12 | #include <string_view> | 
|  | 13 |  | 
|  | 14 | enum class HttpVerb | 
|  | 15 | { | 
|  | 16 | Delete = 0, | 
|  | 17 | Get, | 
|  | 18 | Head, | 
|  | 19 | Options, | 
|  | 20 | Patch, | 
|  | 21 | Post, | 
|  | 22 | Put, | 
|  | 23 | Max, | 
|  | 24 | }; | 
|  | 25 |  | 
| Edward Lee | c0bdf22 | 2022-11-11 23:38:17 +0000 | [diff] [blame] | 26 | static constexpr size_t maxVerbIndex = static_cast<size_t>(HttpVerb::Max) - 1U; | 
|  | 27 |  | 
| Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 28 | inline std::optional<HttpVerb> httpVerbFromBoost(boost::beast::http::verb bv) | 
|  | 29 | { | 
|  | 30 | switch (bv) | 
|  | 31 | { | 
|  | 32 | case boost::beast::http::verb::delete_: | 
|  | 33 | return HttpVerb::Delete; | 
|  | 34 | case boost::beast::http::verb::get: | 
|  | 35 | return HttpVerb::Get; | 
|  | 36 | case boost::beast::http::verb::head: | 
|  | 37 | return HttpVerb::Head; | 
|  | 38 | case boost::beast::http::verb::options: | 
|  | 39 | return HttpVerb::Options; | 
|  | 40 | case boost::beast::http::verb::patch: | 
|  | 41 | return HttpVerb::Patch; | 
|  | 42 | case boost::beast::http::verb::post: | 
|  | 43 | return HttpVerb::Post; | 
|  | 44 | case boost::beast::http::verb::put: | 
|  | 45 | return HttpVerb::Put; | 
|  | 46 | default: | 
|  | 47 | return std::nullopt; | 
|  | 48 | } | 
| Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
|  | 51 | inline std::string_view httpVerbToString(HttpVerb verb) | 
|  | 52 | { | 
|  | 53 | switch (verb) | 
|  | 54 | { | 
|  | 55 | case HttpVerb::Delete: | 
|  | 56 | return "DELETE"; | 
|  | 57 | case HttpVerb::Get: | 
|  | 58 | return "GET"; | 
|  | 59 | case HttpVerb::Head: | 
|  | 60 | return "HEAD"; | 
|  | 61 | case HttpVerb::Patch: | 
|  | 62 | return "PATCH"; | 
|  | 63 | case HttpVerb::Post: | 
|  | 64 | return "POST"; | 
|  | 65 | case HttpVerb::Put: | 
|  | 66 | return "PUT"; | 
|  | 67 | case HttpVerb::Options: | 
|  | 68 | return "OPTIONS"; | 
| Ed Tanous | 4da0490 | 2024-03-19 11:32:44 -0700 | [diff] [blame] | 69 | default: | 
| Ed Tanous | 2c9efc3 | 2022-07-31 22:08:26 -0700 | [diff] [blame] | 70 | return ""; | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | // Should never reach here | 
|  | 74 | return ""; | 
|  | 75 | } |