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