100.00% Lines (3/3) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2019 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_CONFIG_HPP 11   #ifndef BOOST_HTTP_CONFIG_HPP
12   #define BOOST_HTTP_CONFIG_HPP 12   #define BOOST_HTTP_CONFIG_HPP
13   13  
14   #include <boost/http/detail/config.hpp> 14   #include <boost/http/detail/config.hpp>
15   #include <boost/http/header_limits.hpp> 15   #include <boost/http/header_limits.hpp>
16   16  
17   #include <cstddef> 17   #include <cstddef>
18   #include <cstdint> 18   #include <cstdint>
19   #include <memory> 19   #include <memory>
20   20  
21   namespace boost { 21   namespace boost {
22   namespace http { 22   namespace http {
23   23  
24   /** Parser configuration settings. 24   /** Parser configuration settings.
25   25  
26   @see @ref make_parser_config, 26   @see @ref make_parser_config,
27   @ref request_parser, 27   @ref request_parser,
28   @ref response_parser. 28   @ref response_parser.
29   */ 29   */
30   struct parser_config 30   struct parser_config
31   { 31   {
32   /// Limits for HTTP headers. 32   /// Limits for HTTP headers.
33   header_limits headers; 33   header_limits headers;
34   34  
35   /** Maximum content body size (after decoding). 35   /** Maximum content body size (after decoding).
36   36  
37   @see @ref parser::set_body_limit. 37   @see @ref parser::set_body_limit.
38   */ 38   */
39   std::uint64_t body_limit; 39   std::uint64_t body_limit;
40   40  
41   /** Enable Brotli Content-Encoding decoding. 41   /** Enable Brotli Content-Encoding decoding.
42   */ 42   */
43   bool apply_brotli_decoder = false; 43   bool apply_brotli_decoder = false;
44   44  
45   /** Enable Deflate Content-Encoding decoding. 45   /** Enable Deflate Content-Encoding decoding.
46   */ 46   */
47   bool apply_deflate_decoder = false; 47   bool apply_deflate_decoder = false;
48   48  
49   /** Enable Gzip Content-Encoding decoding. 49   /** Enable Gzip Content-Encoding decoding.
50   */ 50   */
51   bool apply_gzip_decoder = false; 51   bool apply_gzip_decoder = false;
52   52  
53   /** Zlib window bits (9-15). 53   /** Zlib window bits (9-15).
54   54  
55   Must be >= the value used during compression. 55   Must be >= the value used during compression.
56   Larger windows improve decompression at the 56   Larger windows improve decompression at the
57   cost of memory. 57   cost of memory.
58   */ 58   */
59   int zlib_window_bits = 15; 59   int zlib_window_bits = 15;
60   60  
61   /** Minimum payload buffer size. 61   /** Minimum payload buffer size.
62   62  
63   Controls: 63   Controls:
64   @li Smallest read/decode buffer allocation 64   @li Smallest read/decode buffer allocation
65   @li Minimum guaranteed in-place body size 65   @li Minimum guaranteed in-place body size
66   @li Reserve size for dynamic buffers when 66   @li Reserve size for dynamic buffers when
67   payload size is unknown 67   payload size is unknown
68   68  
69   This cannot be zero. 69   This cannot be zero.
70   */ 70   */
71   std::size_t min_buffer = 4096; 71   std::size_t min_buffer = 4096;
72   72  
73   /** Maximum buffer size from @ref parser::prepare. 73   /** Maximum buffer size from @ref parser::prepare.
74   74  
75   This cannot be zero. 75   This cannot be zero.
76   */ 76   */
77   std::size_t max_prepare = std::size_t(-1); 77   std::size_t max_prepare = std::size_t(-1);
78   78  
79   /** Constructor. 79   /** Constructor.
80   80  
81   @param server True for server mode (parsing requests, 81   @param server True for server mode (parsing requests,
82   64KB body limit), false for client mode 82   64KB body limit), false for client mode
83   (parsing responses, 1MB body limit). 83   (parsing responses, 1MB body limit).
84   */ 84   */
85   explicit 85   explicit
HITCBC 86   113 parser_config(bool server) noexcept 86   115 parser_config(bool server) noexcept
HITCBC 87   113 : body_limit(server ? 64 * 1024 : 1024 * 1024) 87   115 : body_limit(server ? 64 * 1024 : 1024 * 1024)
88   { 88   {
HITCBC 89   113 } 89   115 }
90   }; 90   };
91   91  
92   /** Parser configuration with computed fields. 92   /** Parser configuration with computed fields.
93   93  
94   Derived from @ref parser_config with additional 94   Derived from @ref parser_config with additional
95   precomputed values for workspace allocation. 95   precomputed values for workspace allocation.
96   96  
97   @see @ref make_parser_config. 97   @see @ref make_parser_config.
98   */ 98   */
99   struct parser_config_impl : parser_config 99   struct parser_config_impl : parser_config
100   { 100   {
101   /// Total workspace allocation size. 101   /// Total workspace allocation size.
102   std::size_t space_needed; 102   std::size_t space_needed;
103   103  
104   /// Space for decompressor state. 104   /// Space for decompressor state.
105   std::size_t max_codec; 105   std::size_t max_codec;
106   106  
107   /// Maximum overread bytes. 107   /// Maximum overread bytes.
108   BOOST_HTTP_DECL 108   BOOST_HTTP_DECL
109   std::size_t 109   std::size_t
110   max_overread() const noexcept; 110   max_overread() const noexcept;
111   }; 111   };
112   112  
113   //------------------------------------------------ 113   //------------------------------------------------
114   114  
115   /** Serializer configuration settings. 115   /** Serializer configuration settings.
116   116  
117   @see @ref make_serializer_config, 117   @see @ref make_serializer_config,
118   @ref serializer. 118   @ref serializer.
119   */ 119   */
120   struct serializer_config 120   struct serializer_config
121   { 121   {
122   /** Enable Brotli Content-Encoding. 122   /** Enable Brotli Content-Encoding.
123   */ 123   */
124   bool apply_brotli_encoder = false; 124   bool apply_brotli_encoder = false;
125   125  
126   /** Enable Deflate Content-Encoding. 126   /** Enable Deflate Content-Encoding.
127   */ 127   */
128   bool apply_deflate_encoder = false; 128   bool apply_deflate_encoder = false;
129   129  
130   /** Enable Gzip Content-Encoding. 130   /** Enable Gzip Content-Encoding.
131   */ 131   */
132   bool apply_gzip_encoder = false; 132   bool apply_gzip_encoder = false;
133   133  
134   /** Brotli compression quality (0-11). 134   /** Brotli compression quality (0-11).
135   135  
136   Higher values yield better but slower compression. 136   Higher values yield better but slower compression.
137   */ 137   */
138   std::uint32_t brotli_comp_quality = 5; 138   std::uint32_t brotli_comp_quality = 5;
139   139  
140   /** Brotli compression window size (10-24). 140   /** Brotli compression window size (10-24).
141   141  
142   Larger windows improve compression but increase 142   Larger windows improve compression but increase
143   memory usage. 143   memory usage.
144   */ 144   */
145   std::uint32_t brotli_comp_window = 18; 145   std::uint32_t brotli_comp_window = 18;
146   146  
147   /** Zlib compression level (0-9). 147   /** Zlib compression level (0-9).
148   148  
149   0 = no compression, 1 = fastest, 9 = best. 149   0 = no compression, 1 = fastest, 9 = best.
150   */ 150   */
151   int zlib_comp_level = 6; 151   int zlib_comp_level = 6;
152   152  
153   /** Zlib window bits (9-15). 153   /** Zlib window bits (9-15).
154   154  
155   Controls the history buffer size. 155   Controls the history buffer size.
156   */ 156   */
157   int zlib_window_bits = 15; 157   int zlib_window_bits = 15;
158   158  
159   /** Zlib memory level (1-9). 159   /** Zlib memory level (1-9).
160   160  
161   Higher values use more memory, but offer faster 161   Higher values use more memory, but offer faster
162   and more efficient compression. 162   and more efficient compression.
163   */ 163   */
164   int zlib_mem_level = 8; 164   int zlib_mem_level = 8;
165   165  
166   /** Minimum buffer size for payloads (must be > 0). 166   /** Minimum buffer size for payloads (must be > 0).
167   */ 167   */
168   std::size_t payload_buffer = 8192; 168   std::size_t payload_buffer = 8192;
169   169  
170   }; 170   };
171   171  
172   //------------------------------------------------ 172   //------------------------------------------------
173   173  
174   struct parser_config_impl; 174   struct parser_config_impl;
175   struct serializer_config_impl; 175   struct serializer_config_impl;
176   176  
177   /** Shared pointer to immutable parser configuration. 177   /** Shared pointer to immutable parser configuration.
178   178  
179   @see @ref parser_config_impl, @ref make_parser_config. 179   @see @ref parser_config_impl, @ref make_parser_config.
180   */ 180   */
181   using shared_parser_config = std::shared_ptr<parser_config_impl const>; 181   using shared_parser_config = std::shared_ptr<parser_config_impl const>;
182   182  
183   /** Shared pointer to immutable serializer configuration. 183   /** Shared pointer to immutable serializer configuration.
184   184  
185   @see @ref serializer_config_impl, @ref make_serializer_config. 185   @see @ref serializer_config_impl, @ref make_serializer_config.
186   */ 186   */
187   using shared_serializer_config = std::shared_ptr<serializer_config_impl const>; 187   using shared_serializer_config = std::shared_ptr<serializer_config_impl const>;
188   188  
189   189  
190   /** Create parser configuration with computed values. 190   /** Create parser configuration with computed values.
191   191  
192   @param cfg User-provided configuration settings. 192   @param cfg User-provided configuration settings.
193   193  
194   @return Shared pointer to configuration with 194   @return Shared pointer to configuration with
195   precomputed fields. 195   precomputed fields.
196   196  
197   @see @ref parser_config, 197   @see @ref parser_config,
198   @ref request_parser, 198   @ref request_parser,
199   @ref response_parser. 199   @ref response_parser.
200   */ 200   */
201   BOOST_HTTP_DECL 201   BOOST_HTTP_DECL
202   shared_parser_config 202   shared_parser_config
203   make_parser_config(parser_config cfg); 203   make_parser_config(parser_config cfg);
204   204  
205   /** Serializer configuration with computed fields. 205   /** Serializer configuration with computed fields.
206   206  
207   Derived from @ref serializer_config with additional 207   Derived from @ref serializer_config with additional
208   precomputed values for workspace allocation. 208   precomputed values for workspace allocation.
209   209  
210   @see @ref make_serializer_config. 210   @see @ref make_serializer_config.
211   */ 211   */
212   struct serializer_config_impl : serializer_config 212   struct serializer_config_impl : serializer_config
213   { 213   {
214   /// Total workspace allocation size. 214   /// Total workspace allocation size.
215   std::size_t space_needed; 215   std::size_t space_needed;
216   }; 216   };
217   217  
218   /** Create serializer configuration with computed values. 218   /** Create serializer configuration with computed values.
219   219  
220   @param cfg User-provided configuration settings. 220   @param cfg User-provided configuration settings.
221   221  
222   @return Shared pointer to configuration with 222   @return Shared pointer to configuration with
223   precomputed fields. 223   precomputed fields.
224   224  
225   @see @ref serializer_config, 225   @see @ref serializer_config,
226   @ref serializer. 226   @ref serializer.
227   */ 227   */
228   BOOST_HTTP_DECL 228   BOOST_HTTP_DECL
229   shared_serializer_config 229   shared_serializer_config
230   make_serializer_config(serializer_config cfg); 230   make_serializer_config(serializer_config cfg);
231   231  
232   } // http 232   } // http
233   } // boost 233   } // boost
234   234  
235   #endif 235   #endif