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