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 <boost/system/error_code.hpp> 15 + #include <system_error>
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 - system::error_code ec; 72 + std::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 - constexpr  
91   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 90   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
92 -  
93 - constexpr  
94   connection_t() = default; 91   connection_t() = default;
95   connection_t( 92   connection_t(
96 - system::error_code ec_, 93 + std::error_code ec_,
97   std::size_t count_, 94   std::size_t count_,
98   bool close_, 95   bool close_,
99   bool keep_alive_, 96   bool keep_alive_,
100   bool upgrade_) noexcept 97   bool upgrade_) noexcept
101   : ec(ec_) 98   : ec(ec_)
102   , count(count_) 99   , count(count_)
103   , close(close_) 100   , close(close_)
104   , keep_alive(keep_alive_) 101   , keep_alive(keep_alive_)
105   , upgrade(upgrade_) 102   , upgrade(upgrade_)
106   { 103   {
107   } 104   }
108   #endif 105   #endif
109   }; 106   };
110   107  
111   //-------------------------------------------- 108   //--------------------------------------------
112   109  
113   /** Metadata for the Content-Encoding field. 110   /** Metadata for the Content-Encoding field.
114   */ 111   */
115   struct content_encoding_t 112   struct content_encoding_t
116   { 113   {
117   /** Error status of Content-Encoding. 114   /** Error status of Content-Encoding.
118   */ 115   */
119 - system::error_code ec; 116 + std::error_code ec;
120   117  
121   /** The total number of fields. 118   /** The total number of fields.
122   */ 119   */
123   std::size_t count = 0; 120   std::size_t count = 0;
124   121  
125   /** The body encoding. 122   /** The body encoding.
126   */ 123   */
127   content_coding coding = 124   content_coding coding =
128   content_coding::identity; 125   content_coding::identity;
129   126  
130 - constexpr  
131   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 127   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
132 -  
133 - constexpr  
134   content_encoding_t() = default; 128   content_encoding_t() = default;
135   content_encoding_t( 129   content_encoding_t(
136 - system::error_code ec_, 130 + std::error_code ec_,
137   std::size_t count_, 131   std::size_t count_,
138   content_coding coding_) noexcept 132   content_coding coding_) noexcept
139   : ec(ec_) 133   : ec(ec_)
140   , count(count_) 134   , count(count_)
141   , coding(coding_) 135   , coding(coding_)
142   { 136   {
143   } 137   }
144   #endif 138   #endif
145   }; 139   };
146   140  
147   //-------------------------------------------- 141   //--------------------------------------------
148   142  
149   /** Metadata for the Content-Length field. 143   /** Metadata for the Content-Length field.
150   */ 144   */
151   struct content_length_t 145   struct content_length_t
152   { 146   {
153   /** Error status of Content-Length. 147   /** Error status of Content-Length.
154   */ 148   */
155 - system::error_code ec; 149 + std::error_code ec;
156   150  
157   /** The total number of fields. 151   /** The total number of fields.
158   */ 152   */
159   std::size_t count = 0; 153   std::size_t count = 0;
160   154  
161   /** The value as an integer. 155   /** The value as an integer.
162   156  
163   This is only valid when ec does 157   This is only valid when ec does
164   not hold a failure, and when 158   not hold a failure, and when
165   count is greater than zero. 159   count is greater than zero.
166   */ 160   */
167   std::uint64_t value = 0; 161   std::uint64_t value = 0;
168   162  
169 - constexpr  
170   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 163   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
171 -  
172 - constexpr  
173   content_length_t() = default; 164   content_length_t() = default;
174   content_length_t( 165   content_length_t(
175 - system::error_code ec_, 166 + std::error_code ec_,
176   std::size_t count_, 167   std::size_t count_,
177   std::uint64_t value_) noexcept 168   std::uint64_t value_) noexcept
178   : ec(ec_) 169   : ec(ec_)
179   , count(count_) 170   , count(count_)
180   , value(value_) 171   , value(value_)
181   { 172   {
182   } 173   }
183   #endif 174   #endif
184   }; 175   };
185   176  
186   //-------------------------------------------- 177   //--------------------------------------------
187   178  
188   /** Metadata for the Expect field. 179   /** Metadata for the Expect field.
189   */ 180   */
190   struct expect_t 181   struct expect_t
191   { 182   {
192   /** Error status of Expect. 183   /** Error status of Expect.
193   */ 184   */
194 - system::error_code ec; 185 + std::error_code ec;
195   186  
196   /** The total number of fields. 187   /** The total number of fields.
197   */ 188   */
198   std::size_t count = 0; 189   std::size_t count = 0;
199   190  
200   /** True if Expect is 100-continue. 191   /** True if Expect is 100-continue.
201   */ 192   */
202   bool is_100_continue = false; 193   bool is_100_continue = false;
203   194  
204 - constexpr  
205   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 195   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
206 -  
207 - constexpr  
208   expect_t() = default; 196   expect_t() = default;
209   expect_t( 197   expect_t(
210 - system::error_code ec_, 198 + std::error_code ec_,
211   std::size_t count_, 199   std::size_t count_,
212   bool is_100_continue_) noexcept 200   bool is_100_continue_) noexcept
213   : ec(ec_) 201   : ec(ec_)
214   , count(count_) 202   , count(count_)
215   , is_100_continue(is_100_continue_) 203   , is_100_continue(is_100_continue_)
216   { 204   {
217   } 205   }
218   #endif 206   #endif
219   }; 207   };
220   208  
221   //-------------------------------------------- 209   //--------------------------------------------
222   210  
223   /** Metadata for the Transfer-Encoding field. 211   /** Metadata for the Transfer-Encoding field.
224   */ 212   */
225   struct transfer_encoding_t 213   struct transfer_encoding_t
226   { 214   {
227   /** Error status of Content-Length. 215   /** Error status of Content-Length.
228   */ 216   */
229 - system::error_code ec; 217 + std::error_code ec;
230   218  
231   /** The total number of fields. 219   /** The total number of fields.
232   */ 220   */
233   std::size_t count = 0; 221   std::size_t count = 0;
234   222  
235   /** True if valid and chunked is specified last. 223   /** True if valid and chunked is specified last.
236   */ 224   */
237   bool is_chunked = false; 225   bool is_chunked = false;
238   226  
239 - constexpr  
240   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 227   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
241 -  
242 - constexpr  
243   transfer_encoding_t() = default; 228   transfer_encoding_t() = default;
244   transfer_encoding_t( 229   transfer_encoding_t(
245 - system::error_code ec_, 230 + std::error_code ec_,
246   std::size_t count_, 231   std::size_t count_,
247   bool is_chunked_) noexcept 232   bool is_chunked_) noexcept
248   : ec(ec_) 233   : ec(ec_)
249   , count(count_) 234   , count(count_)
250   , is_chunked(is_chunked_) 235   , is_chunked(is_chunked_)
251   { 236   {
252   } 237   }
253   #endif 238   #endif
254   }; 239   };
255   240  
256   //-------------------------------------------- 241   //--------------------------------------------
257   242  
258   /** Metadata for Upgrade field. 243   /** Metadata for Upgrade field.
259   */ 244   */
260   struct upgrade_t 245   struct upgrade_t
261   { 246   {
262   /** Error status of Upgrade. 247   /** Error status of Upgrade.
263   */ 248   */
264 - system::error_code ec; 249 + std::error_code ec;
265   250  
266   /** The total number of fields. 251   /** The total number of fields.
267   */ 252   */
268   std::size_t count = 0; 253   std::size_t count = 0;
269   254  
270   /** True if websocket appears at least once. 255   /** True if websocket appears at least once.
271   */ 256   */
272   bool websocket = false; 257   bool websocket = false;
273   258  
274 - constexpr  
275   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND 259   #ifdef BOOST_HTTP_AGGREGATE_WORKAROUND
276 -  
277 - constexpr  
278   upgrade_t() = default; 260   upgrade_t() = default;
279   upgrade_t( 261   upgrade_t(
280 - system::error_code ec_, 262 + std::error_code ec_,
281   std::size_t count_, 263   std::size_t count_,
282   bool websocket_) noexcept 264   bool websocket_) noexcept
283   : ec(ec_) 265   : ec(ec_)
284   , count(count_) 266   , count(count_)
285   , websocket(websocket_) 267   , websocket(websocket_)
286   { 268   {
287   } 269   }
288   #endif 270   #endif
289   }; 271   };
290   272  
291   //-------------------------------------------- 273   //--------------------------------------------
292   274  
293   /** True if payload is manually specified. 275   /** True if payload is manually specified.
294   276  
295   This flag is used to allow the caller 277   This flag is used to allow the caller
296   to resolve problems with non-compliant 278   to resolve problems with non-compliant
297   values for Content-Length. 279   values for Content-Length.
298   */ 280   */
299   bool payload_override = false; 281   bool payload_override = false;
300   282  
301   /** The type of payload. 283   /** The type of payload.
302   */ 284   */
303   http::payload payload = 285   http::payload payload =
304   http::payload::none; 286   http::payload::none;
305   287  
306   /** The size of the payload if known. 288   /** The size of the payload if known.
307   289  
308   This is only valid when @ref payload 290   This is only valid when @ref payload
309   equals @ref http::payload::size. 291   equals @ref http::payload::size.
310   */ 292   */
311   std::uint64_t payload_size = 0; 293   std::uint64_t payload_size = 0;
312   294  
313   //-------------------------------------------- 295   //--------------------------------------------
314   296  
315   // header metadata 297   // header metadata
316   298  
317   /** Metadata for the Connection field. 299   /** Metadata for the Connection field.
318   */ 300   */
319   connection_t connection; 301   connection_t connection;
320   302  
321   /** Metadata for the Content-Encoding field. 303   /** Metadata for the Content-Encoding field.
322   */ 304   */
323   content_encoding_t content_encoding; 305   content_encoding_t content_encoding;
324   306  
325   /** Metadata for the Content-Length field. 307   /** Metadata for the Content-Length field.
326   */ 308   */
327   content_length_t content_length; 309   content_length_t content_length;
328   310  
329   /** Metadata for the Expect field. 311   /** Metadata for the Expect field.
330   */ 312   */
331   expect_t expect; 313   expect_t expect;
332   314  
333   /** Metadata for the Transfer-Encoding field. 315   /** Metadata for the Transfer-Encoding field.
334   */ 316   */
335   transfer_encoding_t transfer_encoding; 317   transfer_encoding_t transfer_encoding;
336   318  
337   /** Metadata for the Upgrade field. 319   /** Metadata for the Upgrade field.
338   */ 320   */
339   upgrade_t upgrade; 321   upgrade_t upgrade;
340   322  
341   //-------------------------------------------- 323   //--------------------------------------------
342   324  
343   /** Constructor. 325   /** Constructor.
344   */ 326   */
HITCBC 345 - 13370 constexpr metadata() = default; 327 + 13415 metadata() = default;
346   }; 328   };
347   329  
348   } // http 330   } // http
349   } // boost 331   } // boost
350   332  
351   #endif 333   #endif