GCC Code Coverage Report


Directory: libs/http_proto/
File: src/request_base.cpp
Date: 2025-06-15 05:10:38
Exec Total Coverage
Lines: 56 56 100.0%
Functions: 2 2 100.0%
Branches: 27 38 71.1%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2024 Christian Mazakas
4 // Copyright (c) 2025 Mohammad Nejati
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // Official repository: https://github.com/cppalliance/http_proto
10 //
11
12 #include <boost/http_proto/request_base.hpp>
13
14 #include <cstring>
15
16 namespace boost {
17 namespace http_proto {
18
19 void
20 20 request_base::
21 set_expect_100_continue(bool b)
22 {
23
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14 times.
20 if(h_.md.expect.count == 0)
24 {
25
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 BOOST_ASSERT(
26 ! h_.md.expect.ec.failed());
27
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 BOOST_ASSERT(
28 ! h_.md.expect.is_100_continue);
29
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if( b )
30 {
31
1/2
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 append(
32 field::expect,
33 "100-continue");
34 4 return;
35 }
36 2 return;
37 }
38
39
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
14 if(h_.md.expect.count == 1)
40 {
41
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6 if(b)
42 {
43
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
4 if(! h_.md.expect.ec.failed())
44 {
45
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 BOOST_ASSERT(
46 h_.md.expect.is_100_continue);
47 2 return;
48 }
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 BOOST_ASSERT(
50 ! h_.md.expect.is_100_continue);
51 2 auto it = find(field::expect);
52
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 BOOST_ASSERT(it != end());
53
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 set(it, "100-continue");
54 2 return;
55 }
56
57 2 auto it = find(field::expect);
58
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 BOOST_ASSERT(it != end());
59 2 erase(it);
60 2 return;
61 }
62
63
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 BOOST_ASSERT(h_.md.expect.ec.failed());
64
65
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 auto nc = (b ? 1 : 0);
66 8 auto ne = h_.md.expect.count - nc;
67
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2 times.
8 if( b )
68
1/2
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
6 set(find(field::expect), "100-continue");
69
70 8 raw_erase_n(field::expect, ne);
71 8 h_.md.expect.count = nc;
72 8 h_.md.expect.ec = {};
73 8 h_.md.expect.is_100_continue = b;
74 }
75
76 //------------------------------------------------
77
78 void
79 31 request_base::
80 set_impl(
81 http_proto::method m,
82 core::string_view ms,
83 core::string_view t,
84 http_proto::version v)
85 {
86 31 auto const vs = to_string(v);
87 auto const new_prefix =
88 31 ms.size() + 1 + // method SP
89 31 t.size() + 1 + // request-target SP
90 31 vs.size() + 2; // HTTP-version CRLF
91
92 // Introduce a new scope so that prefix_op's
93 // destructor runs before h_.on_start_line().
94 {
95 auto op = prefix_op_t(
96
2/2
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 1 times.
31 *this, new_prefix, &ms, &t);
97
98 30 h_.version = v;
99 30 h_.req.method = m;
100 30 h_.req.method_len = static_cast<
101 30 offset_type>(ms.size());
102 30 h_.req.target_len = static_cast<
103 30 offset_type>(t.size());
104
105 30 char* m_dest = h_.buf;
106 30 char* t_dest = h_.buf + ms.size() + 1;
107 30 char* v_dest = t_dest + t.size() + 1;
108
109 30 std::memmove(t_dest, t.data(), t.size());
110 30 t_dest[t.size()] = ' ';
111
112 // memmove after target because could overlap
113 30 std::memmove(m_dest, ms.data(), ms.size());
114 30 m_dest[ms.size()] = ' ';
115
116 30 std::memcpy(v_dest, vs.data(), vs.size());
117 30 v_dest[vs.size() + 0] = '\r';
118 30 v_dest[vs.size() + 1] = '\n';
119 30 }
120
121
1/2
✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
30 h_.on_start_line();
122 30 }
123
124 } // http_proto
125 } // boost
126