GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/request.cpp
Date: 2024-01-12 19:51:55
Exec Total Coverage
Lines: 68 91 74.7%
Functions: 7 8 87.5%
Branches: 14 38 36.8%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 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 #include <boost/http_proto/request.hpp>
11 #include <boost/http_proto/request_view.hpp>
12 #include "detail/copied_strings.hpp"
13 #include "detail/number_string.hpp"
14 #include <utility>
15
16 namespace boost {
17 namespace http_proto {
18
19 34 request::
20 34 request() noexcept
21 : fields_view_base(
22 34 &this->fields_base::h_)
23 , message_base(
24 34 detail::kind::request)
25 {
26 34 }
27
28 366 request::
29 request(
30 366 core::string_view s)
31 : fields_view_base(
32 366 &this->fields_base::h_)
33 , message_base(
34 366 detail::kind::request, s)
35 {
36
37 366 }
38
39 44 request::
40 request(
41 44 request&& other) noexcept
42 : fields_view_base(
43 44 &this->fields_base::h_)
44 , message_base(
45 44 detail::kind::request)
46 {
47 44 swap(other);
48 44 }
49
50 4 request::
51 request(
52 4 request const& other)
53 : fields_view_base(
54 4 &this->fields_base::h_)
55 4 , message_base(*other.ph_)
56 {
57 4 }
58
59 request::
60 request(
61 request_view const& other)
62 : fields_view_base(
63 &this->fields_base::h_)
64 , message_base(*other.ph_)
65 {
66 }
67
68 request&
69 20 request::
70 operator=(
71 request&& other) noexcept
72 {
73 request temp(
74 20 std::move(other));
75 20 temp.swap(*this);
76 20 return *this;
77 }
78
79 //------------------------------------------------
80
81 void
82 2 request::
83 set_expect_100_continue(bool b)
84 {
85
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if(h_.md.expect.count == 0)
86 {
87
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 BOOST_ASSERT(
88 ! h_.md.expect.ec.failed());
89
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 BOOST_ASSERT(
90 ! h_.md.expect.is_100_continue);
91
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(b)
92
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 return append(
93 field::expect,
94 1 "100-continue");
95 return;
96 }
97
98
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(h_.md.expect.count == 1)
99 {
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if(b)
101 {
102 if(! h_.md.expect.ec.failed())
103 {
104 BOOST_ASSERT(
105 h_.md.expect.is_100_continue);
106 return;
107 }
108 BOOST_ASSERT(
109 ! h_.md.expect.is_100_continue);
110 auto it = find(field::expect);
111 BOOST_ASSERT(it != end());
112 erase(it);
113 return;
114 }
115
116 1 auto it = find(field::expect);
117
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 BOOST_ASSERT(it != end());
118 1 erase(it);
119 1 return;
120 }
121
122 if(b)
123 {
124 if(! h_.md.expect.ec.failed())
125 {
126 // remove all but one
127 raw_erase_n(
128 field::expect,
129 h_.md.expect.count - 1);
130 return;
131 }
132
133 erase(field::expect);
134 return append(
135 field::expect,
136 "100-continue");
137 }
138
139 erase(field::expect);
140 }
141
142 //------------------------------------------------
143
144 void
145 10 request::
146 set_impl(
147 http_proto::method m,
148 core::string_view ms,
149 core::string_view t,
150 http_proto::version v)
151 {
152 detail::copied_strings cs(
153 20 this->buffer());
154
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 ms = cs.maybe_copy(ms);
155
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 t = cs.maybe_copy(t);
156
157 auto const vs =
158 10 to_string(v);
159 auto const n =
160 10 ms.size() + 1 +
161 10 t.size() + 1 +
162 10 vs.size() + 2;
163
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 1 times.
10 auto dest = set_prefix_impl(n);
164 9 std::memcpy(
165 dest,
166 9 ms.data(),
167 ms.size());
168 9 dest += ms.size();
169 9 *dest++ = ' ';
170 9 std::memcpy(
171 dest,
172 9 t.data(),
173 t.size());
174 9 dest += t.size();
175 9 *dest++ = ' ';
176 9 std::memcpy(
177 dest,
178 9 vs.data(),
179 vs.size());
180 9 dest += vs.size();
181 9 *dest++ = '\r';
182 9 *dest++ = '\n';
183
184 9 h_.version = v;
185 9 h_.req.method = m;
186 9 h_.req.method_len =
187 9 static_cast<offset_type>(ms.size());
188 9 h_.req.target_len =
189 9 static_cast<offset_type>(t.size());
190
191
1/2
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
9 h_.on_start_line();
192 9 }
193
194 } // http_proto
195 } // boost
196