ゴミ箱
typed_headers.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <optional>
5 #include <type_traits>
6 
9 
10 namespace http {
16  namespace header {
23  template<class M, class H>
24  void set(M& message, H&& header) {
25  static_assert(std::is_base_of<TypedHeader, H>::value, "Provided header doesn't implement TypedHeader interface");
26  message.set(header.name(), header.value());
27  }
28 
34  class TypedHeader {
35  public:
37  virtual boost::beast::string_view name() const = 0;
39  virtual std::string value() const = 0;
40  };
41 
45  class ETag: TypedHeader {
46  public:
53  ETag(const std::string& tag, bool weak);
60  static std::optional<ETag> parse(const std::string& raw_header);
61 
63  bool weak;
65  std::string tag;
66 
67  //TypedHeader interface
68  boost::beast::string_view name() const override;
69  std::string value() const override;
70  };
71 
76  public:
82  explicit Server(const char* name) noexcept;
83 
85  const char* server;
86 
87  //TypedHeader interface
88  boost::beast::string_view name() const override;
89  std::string value() const override;
90  };
91 
96  public:
102  explicit ContentType(const std::string& type);
103  explicit ContentType(const char* type);
104 
106  static ContentType json();
108  static ContentType plain_text();
110  static ContentType html();
112  static ContentType form_url_enc();
114  static ContentType jpeg();
116  static ContentType png();
118  static ContentType octet_stream();
119 
121  std::string type;
122 
123  //TypedHeader interface
124  boost::beast::string_view name() const override;
125  std::string value() const override;
126  };
127 
132  public:
138  explicit UserAgent(const char* name) noexcept;
139 
141  const char* agent;
142 
143  //TypedHeader interface
144  boost::beast::string_view name() const override;
145  std::string value() const override;
146  };
147 
148  }
149 }
std::string type
ContentType&#39;s text.
Definition: typed_headers.hpp:121
const char * agent
UserAgent&#39;s value.
Definition: typed_headers.hpp:141
Definition: type_traits.hpp:25
Definition: typed_headers.hpp:45
virtual std::string value() const =0
Definition: beast_common.hpp:6
const char * server
Header&#39;s value.
Definition: typed_headers.hpp:85
Definition: typed_headers.hpp:75
Definition: typed_headers.hpp:34
Definition: typed_headers.hpp:95
std::string tag
ETag&#39;s value.
Definition: typed_headers.hpp:65
virtual boost::beast::string_view name() const =0
boost::string_ref string_view
The type of string view used by the library.
Definition: string.hpp:36
Definition: type_traits.hpp:22
Definition: typed_headers.hpp:131
bool weak
Weakness flag.
Definition: typed_headers.hpp:63