src/request_builder.cpp

100.0% Lines (26/26) 100.0% List of functions (6/6) 100.0% Branches (13/13)
request_builder.cpp
f(x) Functions (6)
Line Branch TLA Hits Source Code
1 //
2 // Copyright (c) 2026 Mohammad Nejati
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/burl
8 //
9
10 #include <boost/burl/client.hpp>
11
12 #include "detail/base64.hpp"
13
14 #include <string>
15 #include <string_view>
16
17 namespace boost
18 {
19 namespace burl
20 {
21
22 request_builder&&
23 6x request_builder::query(std::string_view key, std::string_view value) &&
24 {
25
1/1
✓ Branch 4 taken 6 times.
6x request_.url.params().append({ key, value });
26 6x return std::move(*this);
27 }
28
29 request_builder&&
30 6x request_builder::header(http::field field, std::string_view value) &&
31 {
32
1/1
✓ Branch 2 taken 6 times.
6x request_.headers.set(field, value);
33 6x return std::move(*this);
34 }
35
36 request_builder&&
37 4x request_builder::header(std::string_view name, std::string_view value) &&
38 {
39
1/1
✓ Branch 3 taken 4 times.
4x request_.headers.set(name, value);
40 4x return std::move(*this);
41 }
42
43 request_builder&&
44 1x request_builder::basic_auth(std::string_view user, std::string_view pass) &&
45 {
46
1/1
✓ Branch 1 taken 1 time.
1x std::string credentials{ user };
47
1/1
✓ Branch 1 taken 1 time.
1x credentials += ':';
48
1/1
✓ Branch 1 taken 1 time.
1x credentials += pass;
49
50
1/1
✓ Branch 1 taken 1 time.
1x std::string value = "Basic ";
51
1/1
✓ Branch 2 taken 1 time.
1x detail::base64_encode(value, credentials);
52
53
1/1
✓ Branch 2 taken 1 time.
1x request_.headers.set(http::field::authorization, value);
54 2x return std::move(*this);
55 1x }
56
57 request_builder&&
58 2x request_builder::bearer_auth(std::string_view token) &&
59 {
60
1/1
✓ Branch 1 taken 2 times.
2x std::string value = "Bearer ";
61
1/1
✓ Branch 1 taken 2 times.
2x value += token;
62
63
1/1
✓ Branch 2 taken 2 times.
2x request_.headers.set(http::field::authorization, value);
64 4x return std::move(*this);
65 2x }
66
67 capy::io_task<response>
68 33x request_builder::send() &&
69 {
70
1/1
✓ Branch 3 taken 33 times.
33x return client_.execute(std::move(request_));
71 }
72
73 } // namespace burl
74 } // namespace boost
75