userver: userver/server/http/http_method.hpp Source File
Loading...
Searching...
No Matches
http_method.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/http/http_method.hpp
4/// @brief @copybrief server::http::HttpMethod
5
6#include <string>
7
8#include <fmt/core.h>
9#include <userver/formats/parse/to.hpp>
10#include <userver/utils/fmt_compat.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace yaml_config {
15class YamlConfig;
16}
17
18namespace server::http {
19
20/// @brief List of HTTP methods
21enum class HttpMethod {
22 kDelete,
23 kGet,
24 kHead,
25 kPost,
26 kPut,
27 kPatch,
28 kConnect,
29 kOptions,
30 kUnknown,
31};
32
33/// @brief Convert HTTP method enum value to string
34const std::string& ToString(HttpMethod method) noexcept;
35
36/// @brief Convert HTTP method string to enum value
37HttpMethod HttpMethodFromString(std::string_view method_str);
38
40
41} // namespace server::http
42
43USERVER_NAMESPACE_END
44
45template <>
46struct fmt::formatter<USERVER_NAMESPACE::server::http::HttpMethod> {
47 constexpr static auto parse(format_parse_context& ctx) { return ctx.begin(); }
48
49 template <typename FormatContext>
50 auto format(USERVER_NAMESPACE::server::http::HttpMethod method, FormatContext& ctx) USERVER_FMT_CONST {
51 return fmt::format_to(ctx.out(), "{}", USERVER_NAMESPACE::server::http::ToString(method));
52 }
53};