src/request_head_base.cpp

100.0% Lines (49/49) 100.0% List of functions (6/6) 73.3% Branches (11/15)
request_head_base.cpp
f(x) Functions (6)
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2021 Vinnie Falco ([email protected])
3 // Copyright (c) 2026 Mohammad Nejati
4 //
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)
7 //
8 // Official repository: https://github.com/cppalliance/burl
9 //
10
11 #include <boost/burl/request_head_base.hpp>
12
13 #include <cstring>
14
15 namespace boost
16 {
17 namespace burl
18 {
19
20 namespace
21 {
22 char buf[] = "GET / HTTP/1.1\r\n\r\n";
23 } // namespace
24
25 240x request_head_base::
26 240x request_head_base() noexcept
27 240x : request_head_base(buf, 0, 2, 16)
28 {
29 240x }
30
31 void
32 8x request_head_base::
33 set_method_(
34 std::string_view s,
35 http::method m)
36 {
37
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8x BOOST_ASSERT(!s.empty());
38 8x splice_prefix_(0, req_.method_len_, s.size(), { 0, s });
39 7x req_.method_ = m;
40 7x req_.method_len_ = static_cast<std::uint16_t>(s.size());
41 7x }
42
43 void
44 93x request_head_base::
45 set_start_line_(
46 std::string_view ms,
47 http::method m,
48 std::string_view t,
49 http::version v)
50 {
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
93x BOOST_ASSERT(!ms.empty());
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
93x BOOST_ASSERT(!t.empty());
53
1/1
✓ Branch 1 taken 93 times.
93x auto const vs = http::to_string(v);
54 370x auto* dest = splice_prefix_(
55 0,
56 93x prefix_,
57
1/1
✓ Branch 2 taken 91 times.
93x ms.size() + 1 + t.size() + 1 + 8 + 2,
58 { 0, ms },
59 93x { ms.size() + 1, t });
60 91x dest += ms.size();
61 91x *dest++ = ' ';
62 91x dest += t.size();
63 91x *dest++ = ' ';
64 91x std::memcpy(dest, vs.data(), 8);
65 91x dest += 8;
66 91x *dest++ = '\r';
67 91x *dest = '\n';
68 91x req_.method_ = m;
69 91x req_.method_len_ = static_cast<std::uint16_t>(ms.size());
70 91x req_.target_len_ = static_cast<std::uint16_t>(t.size());
71 91x set_version_(v);
72 91x }
73
74 void
75 72x request_head_base::
76 set_target(std::string_view s)
77 {
78
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
72x BOOST_ASSERT(!s.empty());
79 72x splice_prefix_(
80 72x req_.method_len_ + 1,
81 72x req_.target_len_,
82 s.size(),
83 { 0, s });
84 67x req_.target_len_ = static_cast<std::uint16_t>(s.size());
85 67x }
86
87 void
88 6x request_head_base::
89 set_version(http::version v)
90 {
91
1/1
✓ Branch 1 taken 6 times.
6x detach_();
92
1/1
✓ Branch 1 taken 6 times.
6x auto const s = http::to_string(v);
93 6x std::memcpy(buf_ - 10, s.data(), 8);
94 6x set_version_(v);
95 6x }
96
97 void
98 6x request_head_base::
99 set_expect_100_continue(bool b)
100 {
101
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
6x if(b)
102
1/1
✓ Branch 2 taken 4 times.
4x set(http::field::expect, "100-continue");
103 else
104 2x erase(http::field::expect);
105 6x }
106
107 } // namespace burl
108 } // namespace boost
109