include/boost/burl/request_head_base.hpp
100.0% Lines (31/31)
100.0% List of functions (12/12)
83.3% Branches (10/12)
Functions (12)
Function
Calls
Lines
Branches
Blocks
boost::burl::request_head_base::request_head_base(char*, unsigned long, unsigned int, unsigned short)
:58
40773x
100.0%
–
100.0%
boost::burl::request_head_base::request_head_base(boost::burl::request_head_base const&)
:68
14x
100.0%
–
100.0%
boost::burl::request_head_base::operator=(boost::burl::request_head_base const&)
:71
17x
100.0%
–
100.0%
boost::burl::request_head_base::swap_(boost::burl::request_head_base&)
:76
18x
100.0%
–
100.0%
boost::burl::request_head_base::method() const
:93
47x
100.0%
–
100.0%
boost::burl::request_head_base::method_text() const
:104
9x
100.0%
–
100.0%
boost::burl::request_head_base::target() const
:115
45x
100.0%
–
100.0%
boost::burl::request_head_base::expect_100_continue() const
:126
33x
100.0%
–
100.0%
boost::burl::request_head_base::set_method(boost::http::method)
:145
6x
100.0%
75.0%
86.0%
boost::burl::request_head_base::set_method(std::basic_string_view<char, std::char_traits<char> >)
:168
2x
100.0%
100.0%
100.0%
boost::burl::request_head_base::set_start_line(boost::http::method, std::basic_string_view<char, std::char_traits<char> >, boost::http::version)
:221
83x
100.0%
75.0%
86.0%
boost::burl::request_head_base::set_start_line(std::basic_string_view<char, std::char_traits<char> >, std::basic_string_view<char, std::char_traits<char> >, boost::http::version)
:255
10x
100.0%
100.0%
100.0%
| 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 | #ifndef BOOST_BURL_REQUEST_HEAD_BASE_HPP | |||
| 12 | #define BOOST_BURL_REQUEST_HEAD_BASE_HPP | |||
| 13 | ||||
| 14 | #include <boost/burl/detail/config.hpp> | |||
| 15 | #include <boost/burl/message_head_base.hpp> | |||
| 16 | ||||
| 17 | namespace boost | |||
| 18 | { | |||
| 19 | namespace burl | |||
| 20 | { | |||
| 21 | ||||
| 22 | /** Mixin for an HTTP request header. | |||
| 23 | ||||
| 24 | This type extends @ref message_head_base with observers | |||
| 25 | and modifiers for the request line | |||
| 26 | ||||
| 27 | Users cannot construct or copy objects of this | |||
| 28 | type; see @ref message_head_base. To build a request | |||
| 29 | header for sending, use @ref request_head or | |||
| 30 | @ref static_request_head. | |||
| 31 | ||||
| 32 | Strings passed to the start-line modifiers are | |||
| 33 | stored verbatim; arguments which are views into | |||
| 34 | the message itself remain valid to pass. | |||
| 35 | */ | |||
| 36 | class request_head_base : public message_head_base | |||
| 37 | { | |||
| 38 | friend class head_parser; | |||
| 39 | ||||
| 40 | BOOST_BURL_DECL | |||
| 41 | void | |||
| 42 | set_method_( | |||
| 43 | std::string_view s, | |||
| 44 | http::method m); | |||
| 45 | ||||
| 46 | BOOST_BURL_DECL | |||
| 47 | void | |||
| 48 | set_start_line_( | |||
| 49 | std::string_view ms, | |||
| 50 | http::method m, | |||
| 51 | std::string_view t, | |||
| 52 | http::version v); | |||
| 53 | ||||
| 54 | protected: | |||
| 55 | BOOST_BURL_DECL | |||
| 56 | request_head_base() noexcept; | |||
| 57 | ||||
| 58 | 40773x | request_head_base( | ||
| 59 | char* base, | |||
| 60 | std::size_t cap, | |||
| 61 | std::uint32_t size = 0, | |||
| 62 | std::uint16_t prefix = 0) noexcept | |||
| 63 | 40773x | : message_head_base( | ||
| 64 | 40773x | true, base, cap, size, prefix) | ||
| 65 | { | |||
| 66 | 40773x | } | ||
| 67 | ||||
| 68 | 14x | request_head_base(request_head_base const&) = default; | ||
| 69 | ||||
| 70 | request_head_base& | |||
| 71 | 17x | operator=(request_head_base const&) = default; | ||
| 72 | ||||
| 73 | ~request_head_base() = default; | |||
| 74 | ||||
| 75 | void | |||
| 76 | 18x | swap_(request_head_base& other) noexcept | ||
| 77 | { | |||
| 78 | 18x | message_head_base::swap_(other); | ||
| 79 | 18x | } | ||
| 80 | ||||
| 81 | public: | |||
| 82 | /** Return the method as a constant. | |||
| 83 | ||||
| 84 | If the stored method string is not a | |||
| 85 | recognized verb, @ref http::method::unknown | |||
| 86 | is returned and @ref method_text holds the | |||
| 87 | original characters. | |||
| 88 | ||||
| 89 | @par Complexity | |||
| 90 | Constant. | |||
| 91 | */ | |||
| 92 | http::method | |||
| 93 | 47x | method() const noexcept | ||
| 94 | { | |||
| 95 | 47x | return req_.method_; | ||
| 96 | } | |||
| 97 | ||||
| 98 | /** Return the method as it appears in the start line. | |||
| 99 | ||||
| 100 | @par Complexity | |||
| 101 | Constant. | |||
| 102 | */ | |||
| 103 | std::string_view | |||
| 104 | 9x | method_text() const noexcept | ||
| 105 | { | |||
| 106 | 9x | return { base_(), req_.method_len_ }; | ||
| 107 | } | |||
| 108 | ||||
| 109 | /** Return the request-target. | |||
| 110 | ||||
| 111 | @par Complexity | |||
| 112 | Constant. | |||
| 113 | */ | |||
| 114 | std::string_view | |||
| 115 | 45x | target() const noexcept | ||
| 116 | { | |||
| 117 | 45x | return { base_() + req_.method_len_ + 1, req_.target_len_ }; | ||
| 118 | } | |||
| 119 | ||||
| 120 | /** Return true if the Expect field is 100-continue. | |||
| 121 | ||||
| 122 | @par Complexity | |||
| 123 | Constant. | |||
| 124 | */ | |||
| 125 | bool | |||
| 126 | 33x | expect_100_continue() const noexcept | ||
| 127 | { | |||
| 128 | 33x | return (flags_ & f_exp_100) != 0; | ||
| 129 | } | |||
| 130 | ||||
| 131 | //-------------------------------------------- | |||
| 132 | ||||
| 133 | /** Set the method using its canonical name. | |||
| 134 | ||||
| 135 | @par Exception Safety | |||
| 136 | Strong guarantee. | |||
| 137 | ||||
| 138 | @throw std::length_error | |||
| 139 | The storage cannot accommodate the change. | |||
| 140 | ||||
| 141 | @param m The method constant. Must not be | |||
| 142 | @ref http::method::unknown. | |||
| 143 | */ | |||
| 144 | void | |||
| 145 | 6x | set_method(http::method m) | ||
| 146 | { | |||
| 147 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6x | BOOST_ASSERT(m != http::method::unknown); | |
| 148 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 5 taken 6 times.
|
6x | set_method_(http::to_string(m), m); | |
| 149 | 6x | } | ||
| 150 | ||||
| 151 | /** Set the method from a string. | |||
| 152 | ||||
| 153 | The string is stored verbatim. When it | |||
| 154 | equals a known method name, the | |||
| 155 | corresponding constant is returned by | |||
| 156 | @ref method. | |||
| 157 | ||||
| 158 | @par Exception Safety | |||
| 159 | Strong guarantee. | |||
| 160 | ||||
| 161 | @throw std::length_error | |||
| 162 | The storage cannot accommodate the change. | |||
| 163 | ||||
| 164 | @param s The method string. Must not be | |||
| 165 | empty. | |||
| 166 | */ | |||
| 167 | void | |||
| 168 | 2x | set_method(std::string_view s) | ||
| 169 | { | |||
| 170 |
2/2✓ Branch 2 taken 2 times.
✓ Branch 5 taken 1 time.
|
2x | set_method_(s, http::string_to_method(s)); | |
| 171 | 1x | } | ||
| 172 | ||||
| 173 | /** Set the request-target. | |||
| 174 | ||||
| 175 | The string is stored verbatim. | |||
| 176 | ||||
| 177 | @par Exception Safety | |||
| 178 | Strong guarantee. | |||
| 179 | ||||
| 180 | @throw std::length_error | |||
| 181 | The storage cannot accommodate the change. | |||
| 182 | ||||
| 183 | @param s The request-target. Must not be | |||
| 184 | empty. | |||
| 185 | */ | |||
| 186 | BOOST_BURL_DECL | |||
| 187 | void | |||
| 188 | set_target(std::string_view s); | |||
| 189 | ||||
| 190 | /** Set the HTTP version. | |||
| 191 | ||||
| 192 | @par Exception Safety | |||
| 193 | Strong guarantee. | |||
| 194 | ||||
| 195 | @param v The version. | |||
| 196 | */ | |||
| 197 | BOOST_BURL_DECL | |||
| 198 | void | |||
| 199 | set_version(http::version v); | |||
| 200 | ||||
| 201 | /** Set the entire request line. | |||
| 202 | ||||
| 203 | The method, target, and version are | |||
| 204 | replaced in a single operation. | |||
| 205 | ||||
| 206 | @par Exception Safety | |||
| 207 | Strong guarantee. | |||
| 208 | ||||
| 209 | @throw std::length_error | |||
| 210 | The storage cannot accommodate the change. | |||
| 211 | ||||
| 212 | @param m The method constant. Must not be | |||
| 213 | @ref http::method::unknown. | |||
| 214 | ||||
| 215 | @param t The request-target. Must not be | |||
| 216 | empty. | |||
| 217 | ||||
| 218 | @param v The version. | |||
| 219 | */ | |||
| 220 | void | |||
| 221 | 83x | set_start_line( | ||
| 222 | http::method m, | |||
| 223 | std::string_view t, | |||
| 224 | http::version v = | |||
| 225 | http::version::http_1_1) | |||
| 226 | { | |||
| 227 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 83 times.
|
83x | BOOST_ASSERT(m != http::method::unknown); | |
| 228 |
2/2✓ Branch 1 taken 83 times.
✓ Branch 5 taken 82 times.
|
83x | set_start_line_(http::to_string(m), m, t, v); | |
| 229 | 82x | } | ||
| 230 | ||||
| 231 | /** Set the entire request line, with the | |||
| 232 | method as a string. | |||
| 233 | ||||
| 234 | The method, target, and version are | |||
| 235 | replaced in a single operation. The method | |||
| 236 | string is stored verbatim. When it equals a | |||
| 237 | known method name, the corresponding | |||
| 238 | constant is returned by @ref method. | |||
| 239 | ||||
| 240 | @par Exception Safety | |||
| 241 | Strong guarantee. | |||
| 242 | ||||
| 243 | @throw std::length_error | |||
| 244 | The storage cannot accommodate the change. | |||
| 245 | ||||
| 246 | @param m The method string. Must not be | |||
| 247 | empty. | |||
| 248 | ||||
| 249 | @param t The request-target. Must not be | |||
| 250 | empty. | |||
| 251 | ||||
| 252 | @param v The version. | |||
| 253 | */ | |||
| 254 | void | |||
| 255 | 10x | set_start_line( | ||
| 256 | std::string_view m, | |||
| 257 | std::string_view t, | |||
| 258 | http::version v = | |||
| 259 | http::version::http_1_1) | |||
| 260 | { | |||
| 261 |
2/2✓ Branch 2 taken 10 times.
✓ Branch 5 taken 9 times.
|
10x | set_start_line_(m, http::string_to_method(m), t, v); | |
| 262 | 9x | } | ||
| 263 | ||||
| 264 | /** Add or remove the Expect: 100-continue field. | |||
| 265 | ||||
| 266 | @par Exception Safety | |||
| 267 | Strong guarantee. | |||
| 268 | ||||
| 269 | @throw std::length_error | |||
| 270 | The storage cannot accommodate the field. | |||
| 271 | ||||
| 272 | @param b Whether the field should be present. | |||
| 273 | */ | |||
| 274 | BOOST_BURL_DECL | |||
| 275 | void | |||
| 276 | set_expect_100_continue(bool b); | |||
| 277 | }; | |||
| 278 | ||||
| 279 | } // namespace burl | |||
| 280 | } // namespace boost | |||
| 281 | ||||
| 282 | #endif | |||
| 283 |