blob: dd5af4024d0dbe6b332704ffbcd9843b81be5493 [file] [log] [blame]
Ed Tanous2c9efc32022-07-31 22:08:26 -07001#pragma once
2
3#include <boost/beast/http/verb.hpp>
4
5#include <optional>
6#include <string_view>
7
8enum class HttpVerb
9{
10 Delete = 0,
11 Get,
12 Head,
13 Options,
14 Patch,
15 Post,
16 Put,
17 Max,
18};
19
Edward Leec0bdf222022-11-11 23:38:17 +000020static constexpr size_t maxVerbIndex = static_cast<size_t>(HttpVerb::Max) - 1U;
21
Ed Tanous2c9efc32022-07-31 22:08:26 -070022inline 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 Tanous2c9efc32022-07-31 22:08:26 -070043}
44
45inline 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 Tanous4da04902024-03-19 11:32:44 -070063 default:
Ed Tanous2c9efc32022-07-31 22:08:26 -070064 return "";
65 }
66
67 // Should never reach here
68 return "";
69}