libs/http/src/config.cpp
95.7% Lines (22/23)
100.0% Functions (3/3)
80.0% Branches (4/5)
libs/http/src/config.cpp
| Line | Branch | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2026 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // | ||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 6 | // | ||
| 7 | // Official repository: https://github.com/cppalliance/http | ||
| 8 | // | ||
| 9 | |||
| 10 | #include <boost/http/config.hpp> | ||
| 11 | #include <boost/http/detail/except.hpp> | ||
| 12 | #include <boost/http/detail/header.hpp> | ||
| 13 | |||
| 14 | #include <cstdint> | ||
| 15 | #include <memory> | ||
| 16 | |||
| 17 | namespace boost { | ||
| 18 | namespace http { | ||
| 19 | |||
| 20 | std::size_t | ||
| 21 | 73736 | parser_config_impl:: | |
| 22 | max_overread() const noexcept | ||
| 23 | { | ||
| 24 | 73736 | return headers.max_size + min_buffer; | |
| 25 | } | ||
| 26 | |||
| 27 | std::shared_ptr<parser_config_impl const> | ||
| 28 | 30 | make_parser_config(parser_config cfg) | |
| 29 | { | ||
| 30 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 30 times.
|
30 | if(cfg.max_prepare < 1) |
| 31 | ✗ | detail::throw_invalid_argument(); | |
| 32 | |||
| 33 |
1/1✓ Branch 2 taken 30 times.
|
30 | auto impl = std::make_shared<parser_config_impl>(std::move(cfg)); |
| 34 | |||
| 35 | /* | ||
| 36 | | fb | cb0 | cb1 | T | f | | ||
| 37 | |||
| 38 | fb flat_dynamic_buffer headers.max_size | ||
| 39 | cb0 circular_buffer min_buffer | ||
| 40 | cb1 circular_buffer min_buffer | ||
| 41 | f table max_table_space | ||
| 42 | */ | ||
| 43 | |||
| 44 | 30 | std::size_t space_needed = 0; | |
| 45 | |||
| 46 |
1/1✓ Branch 2 taken 30 times.
|
30 | space_needed += impl->headers.valid_space_needed(); |
| 47 | |||
| 48 | // cb0_, cb1_ | ||
| 49 | 30 | space_needed += impl->min_buffer + impl->min_buffer; | |
| 50 | |||
| 51 | // round up to alignof(detail::header::entry) | ||
| 52 | 30 | auto const al = alignof(detail::header::entry); | |
| 53 | 30 | space_needed = al * ((space_needed + al - 1) / al); | |
| 54 | |||
| 55 | 30 | impl->space_needed = space_needed; | |
| 56 | 30 | impl->max_codec = 0; // not currently used for parser | |
| 57 | |||
| 58 | 60 | return impl; | |
| 59 | 30 | } | |
| 60 | |||
| 61 | std::shared_ptr<serializer_config_impl const> | ||
| 62 | 3 | make_serializer_config(serializer_config cfg) | |
| 63 | { | ||
| 64 |
1/1✓ Branch 1 taken 3 times.
|
3 | auto impl = std::make_shared<serializer_config_impl>(); |
| 65 | 3 | static_cast<serializer_config&>(*impl) = std::move(cfg); | |
| 66 | |||
| 67 | 3 | std::size_t space_needed = 0; | |
| 68 | 3 | space_needed += impl->payload_buffer; | |
| 69 | |||
| 70 | 3 | impl->space_needed = space_needed; | |
| 71 | |||
| 72 | 6 | return impl; | |
| 73 | 3 | } | |
| 74 | |||
| 75 | } // http | ||
| 76 | } // boost | ||
| 77 |