GCC Code Coverage Report


Directory: libs/http_proto/
File: include/boost/http_proto/impl/parser.hpp
Date: 2025-09-21 18:08:15
Exec Total Coverage
Lines: 20 26 76.9%
Functions: 5 5 100.0%
Branches: 6 12 50.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2019 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_proto
8 //
9
10 // we need a pragma once for the circular includes required
11 // clangd's intellisense
12 #pragma once
13
14 #ifndef BOOST_HTTP_PROTO_IMPL_PARSER_HPP
15 #define BOOST_HTTP_PROTO_IMPL_PARSER_HPP
16
17 #include <boost/http_proto/parser.hpp>
18 #include <boost/http_proto/sink.hpp>
19 #include <boost/http_proto/detail/type_traits.hpp>
20
21 namespace boost {
22 namespace http_proto {
23
24 template<class ElasticBuffer>
25 typename std::enable_if<
26 ! detail::is_reference_wrapper<
27 ElasticBuffer>::value &&
28 ! is_sink<ElasticBuffer>::value>::type
29 11 parser::
30 set_body(
31 ElasticBuffer&& eb)
32 {
33 // If this goes off it means you are trying
34 // to pass by lvalue reference. Use std::ref
35 // instead.
36 static_assert(
37 ! std::is_reference<ElasticBuffer>::value,
38 "Use std::ref instead of pass-by-reference");
39
40 // Check ElasticBuffer type requirements
41 static_assert(
42 buffers::is_dynamic_buffer<ElasticBuffer>::value,
43 "Type requirements not met.");
44
45 // body must not already be set
46
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if(is_body_set())
47 detail::throw_logic_error();
48
49 // headers must be complete
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if(! got_header())
51 detail::throw_logic_error();
52
53 11 auto& dyn = ws().emplace<
54 buffers::any_dynamic_buffer_impl<typename
55 std::decay<ElasticBuffer>::type,
56 11 buffers_N>>(std::forward<ElasticBuffer>(eb));
57
58 11 set_body_impl(dyn);
59 11 }
60
61 template<class ElasticBuffer>
62 void
63 372 parser::
64 set_body(
65 std::reference_wrapper<ElasticBuffer> eb)
66 {
67 // Check ElasticBuffer type requirements
68 static_assert(
69 buffers::is_dynamic_buffer<ElasticBuffer>::value,
70 "Type requirements not met.");
71
72 // body must not already be set
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
372 if(is_body_set())
74 detail::throw_logic_error();
75
76 // headers must be complete
77
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
372 if(! got_header())
78 detail::throw_logic_error();
79
80 372 auto& dyn = ws().emplace<
81 buffers::any_dynamic_buffer_impl<typename
82 std::decay<ElasticBuffer>::type&,
83 372 buffers_N>>(eb);
84
85 372 set_body_impl(dyn);
86 372 }
87
88 template<
89 class Sink,
90 class... Args,
91 class>
92 Sink&
93 372 parser::
94 set_body(Args&&... args)
95 {
96 // body must not already be set
97
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
372 if(is_body_set())
98 detail::throw_logic_error();
99
100 // headers must be complete
101
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 372 times.
372 if(! got_header())
102 detail::throw_logic_error();
103
104 372 auto& s = ws().emplace<Sink>(
105 std::forward<Args>(args)...);
106
107 372 set_body_impl(s);
108 372 return s;
109 }
110
111 } // http_proto
112 } // boost
113
114 #endif
115