100.00% Lines (1/1) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2024 Mohammad Nejati 3   // Copyright (c) 2024 Mohammad Nejati
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/cppalliance/http 8   // Official repository: https://github.com/cppalliance/http
9   // 9   //
10   10  
11   #ifndef BOOST_HTTP_METADATA_HPP 11   #ifndef BOOST_HTTP_METADATA_HPP
12   #define BOOST_HTTP_METADATA_HPP 12   #define BOOST_HTTP_METADATA_HPP
13   13  
14   #include <boost/http/detail/config.hpp> 14   #include <boost/http/detail/config.hpp>
15 - #include <system_error> 15 + #include <boost/system/error_code.hpp>
16   #include <cstdint> 16   #include <cstdint>
17   #include <cstdlib> 17   #include <cstdlib>
18   18  
19   namespace boost { 19   namespace boost {
20   namespace http { 20   namespace http {
21   21  
22   /** Identifies the payload type of a message. 22   /** Identifies the payload type of a message.
23   */ 23   */
24   enum class payload : unsigned char 24   enum class payload : unsigned char
25   { 25   {
26   /** This message has no payload. 26   /** This message has no payload.
27   */ 27   */
28   none, 28   none,
29   29  
30   /** The payload is unknown due to errors. 30   /** The payload is unknown due to errors.
31   */ 31   */
32   error, 32   error,
33   33  
34   /** This message has a known payload size. 34   /** This message has a known payload size.
35   */ 35   */
36   size, 36   size,
37   37  
38   /** This message contains a chunked payload. 38   /** This message contains a chunked payload.
39   */ 39   */
40   chunked, 40   chunked,
41   41  
42   /** The payload for this message continues until EOF. 42   /** The payload for this message continues until EOF.
43   */ 43   */
44   to_eof 44   to_eof
45   }; 45   };
46   46  
47   /** Standard content-codings for HTTP message bodies. 47   /** Standard content-codings for HTTP message bodies.
48   */ 48   */
49   enum class content_coding 49   enum class content_coding
50   { 50   {
51   unknown, 51   unknown,
52   br, 52   br,
53   compress, 53   compress,
54   dcb, 54   dcb,
55   dcz, 55   dcz,
56   deflate, 56   deflate,
57   gzip, 57   gzip,
58   identity, 58   identity,
59   zstd, 59   zstd,
60   }; 60   };
61   61  
62   /** Metadata about a request or response. 62   /** Metadata about a request or response.
63   */ 63   */
64   struct metadata 64   struct metadata
65   { 65   {
66   /** Metadata for the Connection field. 66   /** Metadata for the Connection field.
67   */ 67   */
68   struct connection_t 68   struct connection_t
69   { 69   {
70   /** Error status of Connection. 70   /** Error status of Connection.
71   */ 71   */
72 - std::error_code ec; 72 + system::error_code ec;
73   73  
74   /** The total number of fields. 74   /** The total number of fields.
75   */ 75   */
76   std::size_t count = 0; 76   std::size_t count = 0;
77   77  
78   /** true if a close token is present. 78   /** true if a close token is present.
79   */ 79   */
80   bool close = false; 80   bool close = false;
81   81  
82   /** true if a keep-alive token is present. 82   /** true if a keep-alive token is present.
83   */ 83   */
84   bool keep_alive = false; 84   bool keep_alive = false;
85   85  
86   /** true if an upgrade token is present. 86   /** true if an upgrade token is present.
87   */ 87   */
88   bool upgrade = false; 88   bool upgrade = false;
89   89  
90   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 90   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
  91 + constexpr
91   connection_t() = default; 92   connection_t() = default;
  93 +
  94 + constexpr
92   connection_t( 95   connection_t(
93 - std::error_code ec_, 96 + system::error_code ec_,
94   std::size_t count_, 97   std::size_t count_,
95   bool close_, 98   bool close_,
96   bool keep_alive_, 99   bool keep_alive_,
97   bool upgrade_) noexcept 100   bool upgrade_) noexcept
98   : ec(ec_) 101   : ec(ec_)
99   , count(count_) 102   , count(count_)
100   , close(close_) 103   , close(close_)
101   , keep_alive(keep_alive_) 104   , keep_alive(keep_alive_)
102   , upgrade(upgrade_) 105   , upgrade(upgrade_)
103   { 106   {
104   } 107   }
105   #endif 108   #endif
106   }; 109   };
107   110  
108   //-------------------------------------------- 111   //--------------------------------------------
109   112  
110   /** Metadata for the Content-Encoding field. 113   /** Metadata for the Content-Encoding field.
111   */ 114   */
112   struct content_encoding_t 115   struct content_encoding_t
113   { 116   {
114   /** Error status of Content-Encoding. 117   /** Error status of Content-Encoding.
115   */ 118   */
116 - std::error_code ec; 119 + system::error_code ec;
117   120  
118   /** The total number of fields. 121   /** The total number of fields.
119   */ 122   */
120   std::size_t count = 0; 123   std::size_t count = 0;
121   124  
122   /** The body encoding. 125   /** The body encoding.
123   */ 126   */
124   content_coding coding = 127   content_coding coding =
125   content_coding::identity; 128   content_coding::identity;
126   129  
127   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 130   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
  131 + constexpr
128   content_encoding_t() = default; 132   content_encoding_t() = default;
  133 +
  134 + constexpr
129   content_encoding_t( 135   content_encoding_t(
130 - std::error_code ec_, 136 + system::error_code ec_,
131   std::size_t count_, 137   std::size_t count_,
132   content_coding coding_) noexcept 138   content_coding coding_) noexcept
133   : ec(ec_) 139   : ec(ec_)
134   , count(count_) 140   , count(count_)
135   , coding(coding_) 141   , coding(coding_)
136   { 142   {
137   } 143   }
138   #endif 144   #endif
139   }; 145   };
140   146  
141   //-------------------------------------------- 147   //--------------------------------------------
142   148  
143   /** Metadata for the Content-Length field. 149   /** Metadata for the Content-Length field.
144   */ 150   */
145   struct content_length_t 151   struct content_length_t
146   { 152   {
147   /** Error status of Content-Length. 153   /** Error status of Content-Length.
148   */ 154   */
149 - std::error_code ec; 155 + system::error_code ec;
150   156  
151   /** The total number of fields. 157   /** The total number of fields.
152   */ 158   */
153   std::size_t count = 0; 159   std::size_t count = 0;
154   160  
155   /** The value as an integer. 161   /** The value as an integer.
156   162  
157   This is only valid when ec does 163   This is only valid when ec does
158   not hold a failure, and when 164   not hold a failure, and when
159   count is greater than zero. 165   count is greater than zero.
160   */ 166   */
161   std::uint64_t value = 0; 167   std::uint64_t value = 0;
162   168  
163   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 169   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
  170 + constexpr
164   content_length_t() = default; 171   content_length_t() = default;
  172 +
  173 + constexpr
165   content_length_t( 174   content_length_t(
166 - std::error_code ec_, 175 + system::error_code ec_,
167   std::size_t count_, 176   std::size_t count_,
168   std::uint64_t value_) noexcept 177   std::uint64_t value_) noexcept
169   : ec(ec_) 178   : ec(ec_)
170   , count(count_) 179   , count(count_)
171   , value(value_) 180   , value(value_)
172   { 181   {
173   } 182   }
174   #endif 183   #endif
175   }; 184   };
176   185  
177   //-------------------------------------------- 186   //--------------------------------------------
178   187  
179   /** Metadata for the Expect field. 188   /** Metadata for the Expect field.
180   */ 189   */
181   struct expect_t 190   struct expect_t
182   { 191   {
183   /** Error status of Expect. 192   /** Error status of Expect.
184   */ 193   */
185 - std::error_code ec; 194 + system::error_code ec;
186   195  
187   /** The total number of fields. 196   /** The total number of fields.
188   */ 197   */
189   std::size_t count = 0; 198   std::size_t count = 0;
190   199  
191   /** True if Expect is 100-continue. 200   /** True if Expect is 100-continue.
192   */ 201   */
193   bool is_100_continue = false; 202   bool is_100_continue = false;
194   203  
195   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 204   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
  205 + constexpr
196   expect_t() = default; 206   expect_t() = default;
  207 +
  208 + constexpr
197   expect_t( 209   expect_t(
198 - std::error_code ec_, 210 + system::error_code ec_,
199   std::size_t count_, 211   std::size_t count_,
200   bool is_100_continue_) noexcept 212   bool is_100_continue_) noexcept
201   : ec(ec_) 213   : ec(ec_)
202   , count(count_) 214   , count(count_)
203   , is_100_continue(is_100_continue_) 215   , is_100_continue(is_100_continue_)
204   { 216   {
205   } 217   }
206   #endif 218   #endif
207   }; 219   };
208   220  
209   //-------------------------------------------- 221   //--------------------------------------------
210   222  
211   /** Metadata for the Transfer-Encoding field. 223   /** Metadata for the Transfer-Encoding field.
212   */ 224   */
213   struct transfer_encoding_t 225   struct transfer_encoding_t
214   { 226   {
215   /** Error status of Content-Length. 227   /** Error status of Content-Length.
216   */ 228   */
217 - std::error_code ec; 229 + system::error_code ec;
218   230  
219   /** The total number of fields. 231   /** The total number of fields.
220   */ 232   */
221   std::size_t count = 0; 233   std::size_t count = 0;
222   234  
223   /** True if valid and chunked is specified last. 235   /** True if valid and chunked is specified last.
224   */ 236   */
225   bool is_chunked = false; 237   bool is_chunked = false;
226   238  
227   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 239   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
  240 + constexpr
228   transfer_encoding_t() = default; 241   transfer_encoding_t() = default;
  242 +
  243 + constexpr
229   transfer_encoding_t( 244   transfer_encoding_t(
230 - std::error_code ec_, 245 + system::error_code ec_,
231   std::size_t count_, 246   std::size_t count_,
232   bool is_chunked_) noexcept 247   bool is_chunked_) noexcept
233   : ec(ec_) 248   : ec(ec_)
234   , count(count_) 249   , count(count_)
235   , is_chunked(is_chunked_) 250   , is_chunked(is_chunked_)
236   { 251   {
237   } 252   }
238   #endif 253   #endif
239   }; 254   };
240   255  
241   //-------------------------------------------- 256   //--------------------------------------------
242   257  
243   /** Metadata for Upgrade field. 258   /** Metadata for Upgrade field.
244   */ 259   */
245   struct upgrade_t 260   struct upgrade_t
246   { 261   {
247   /** Error status of Upgrade. 262   /** Error status of Upgrade.
248   */ 263   */
249 - std::error_code ec; 264 + system::error_code ec;
250   265  
251   /** The total number of fields. 266   /** The total number of fields.
252   */ 267   */
253   std::size_t count = 0; 268   std::size_t count = 0;
254   269  
255   /** True if websocket appears at least once. 270   /** True if websocket appears at least once.
256   */ 271   */
257   bool websocket = false; 272   bool websocket = false;
258   273  
259   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 274   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
  275 + constexpr
260   upgrade_t() = default; 276   upgrade_t() = default;
  277 +
  278 + constexpr
261   upgrade_t( 279   upgrade_t(
262 - std::error_code ec_, 280 + system::error_code ec_,
263   std::size_t count_, 281   std::size_t count_,
264   bool websocket_) noexcept 282   bool websocket_) noexcept
265   : ec(ec_) 283   : ec(ec_)
266   , count(count_) 284   , count(count_)
267   , websocket(websocket_) 285   , websocket(websocket_)
268   { 286   {
269   } 287   }
270   #endif 288   #endif
271   }; 289   };
272   290  
273   //-------------------------------------------- 291   //--------------------------------------------
274   292  
275   /** True if payload is manually specified. 293   /** True if payload is manually specified.
276   294  
277   This flag is used to allow the caller 295   This flag is used to allow the caller
278   to resolve problems with non-compliant 296   to resolve problems with non-compliant
279   values for Content-Length. 297   values for Content-Length.
280   */ 298   */
281   bool payload_override = false; 299   bool payload_override = false;
282   300  
283   /** The type of payload. 301   /** The type of payload.
284   */ 302   */
285   http::payload payload = 303   http::payload payload =
286   http::payload::none; 304   http::payload::none;
287   305  
288   /** The size of the payload if known. 306   /** The size of the payload if known.
289   307  
290   This is only valid when @ref payload 308   This is only valid when @ref payload
291   equals @ref http::payload::size. 309   equals @ref http::payload::size.
292   */ 310   */
293   std::uint64_t payload_size = 0; 311   std::uint64_t payload_size = 0;
294   312  
295   //-------------------------------------------- 313   //--------------------------------------------
296   314  
297   // header metadata 315   // header metadata
298   316  
299   /** Metadata for the Connection field. 317   /** Metadata for the Connection field.
300   */ 318   */
301   connection_t connection; 319   connection_t connection;
302   320  
303   /** Metadata for the Content-Encoding field. 321   /** Metadata for the Content-Encoding field.
304   */ 322   */
305   content_encoding_t content_encoding; 323   content_encoding_t content_encoding;
306   324  
307   /** Metadata for the Content-Length field. 325   /** Metadata for the Content-Length field.
308   */ 326   */
309   content_length_t content_length; 327   content_length_t content_length;
310   328  
311   /** Metadata for the Expect field. 329   /** Metadata for the Expect field.
312   */ 330   */
313   expect_t expect; 331   expect_t expect;
314   332  
315   /** Metadata for the Transfer-Encoding field. 333   /** Metadata for the Transfer-Encoding field.
316   */ 334   */
317   transfer_encoding_t transfer_encoding; 335   transfer_encoding_t transfer_encoding;
318   336  
319   /** Metadata for the Upgrade field. 337   /** Metadata for the Upgrade field.
320   */ 338   */
321   upgrade_t upgrade; 339   upgrade_t upgrade;
322   340  
323   //-------------------------------------------- 341   //--------------------------------------------
324   342  
325   /** Constructor. 343   /** Constructor.
326   */ 344   */
HITCBC 327 - 13415 metadata() = default; 345 + 13370 constexpr metadata() = default;
328   }; 346   };
329   347  
330   } // http 348   } // http
331   } // boost 349   } // boost
332   350  
333   #endif 351   #endif