blob: 33dd5690dcecf5be0fab5e0c8b3b21a6682bba9a [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
20inline std::optional<HttpVerb> httpVerbFromBoost(boost::beast::http::verb bv)
21{
22 switch (bv)
23 {
24 case boost::beast::http::verb::delete_:
25 return HttpVerb::Delete;
26 case boost::beast::http::verb::get:
27 return HttpVerb::Get;
28 case boost::beast::http::verb::head:
29 return HttpVerb::Head;
30 case boost::beast::http::verb::options:
31 return HttpVerb::Options;
32 case boost::beast::http::verb::patch:
33 return HttpVerb::Patch;
34 case boost::beast::http::verb::post:
35 return HttpVerb::Post;
36 case boost::beast::http::verb::put:
37 return HttpVerb::Put;
38 default:
39 return std::nullopt;
40 }
41
42 return std::nullopt;
43}
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";
63 case HttpVerb::Max:
64 return "";
65 }
66
67 // Should never reach here
68 return "";
69}