Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) | ||
3 | // Copyright (c) 2024 Christian Mazakas | ||
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/http_proto | ||
9 | // | ||
10 | |||
11 | #include <boost/http_proto/response.hpp> | ||
12 | #include <boost/http_proto/response_view.hpp> | ||
13 | #include <boost/http_proto/version.hpp> | ||
14 | |||
15 | #include <utility> | ||
16 | |||
17 | #include "detail/header_impl.hpp" | ||
18 | |||
19 | namespace boost { | ||
20 | namespace http_proto { | ||
21 | |||
22 | 66 | response:: | |
23 | 66 | response() noexcept | |
24 | : fields_view_base( | ||
25 | 66 | &this->fields_base::h_) | |
26 | , message_base( | ||
27 | 66 | detail::kind::response) | |
28 | { | ||
29 | 66 | } | |
30 | |||
31 | 176 | response:: | |
32 | response( | ||
33 | 176 | core::string_view s) | |
34 | : fields_view_base( | ||
35 | 176 | &this->fields_base::h_) | |
36 | , message_base( | ||
37 | 176 | detail::kind::response, s) | |
38 | { | ||
39 | 176 | } | |
40 | |||
41 | 6 | response:: | |
42 | response( | ||
43 | 6 | response&& other) noexcept | |
44 | 6 | : response() | |
45 | { | ||
46 | 6 | swap(other); | |
47 | 6 | } | |
48 | |||
49 | 4 | response:: | |
50 | response( | ||
51 | 4 | response const& other) | |
52 | : fields_view_base( | ||
53 | 4 | &this->fields_base::h_) | |
54 | 4 | , message_base(*other.ph_) | |
55 | { | ||
56 | 4 | } | |
57 | |||
58 | 4 | response:: | |
59 | response( | ||
60 | 4 | response_view const& other) | |
61 | : fields_view_base( | ||
62 | 4 | &this->fields_base::h_) | |
63 | 4 | , message_base(*other.ph_) | |
64 | { | ||
65 | 4 | } | |
66 | |||
67 | response& | ||
68 | 1 | response:: | |
69 | operator=( | ||
70 | response&& other) noexcept | ||
71 | { | ||
72 | response temp( | ||
73 | 1 | std::move(other)); | |
74 | 1 | temp.swap(*this); | |
75 | 1 | return *this; | |
76 | } | ||
77 | |||
78 | 12 | response:: | |
79 | response( | ||
80 | 12 | http_proto::status sc) | |
81 | : response( | ||
82 | 12 | sc, http_proto::version::http_1_1) | |
83 | { | ||
84 | 12 | } | |
85 | |||
86 | 28 | response:: | |
87 | response( | ||
88 | http_proto::status sc, | ||
89 | 28 | http_proto::version v) | |
90 | 28 | : response() | |
91 | { | ||
92 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 10 times.
|
28 | if( sc != h_.res.status || |
93 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
8 | v != h_.version) |
94 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
22 | set_start_line(sc, v); |
95 | 28 | } | |
96 | |||
97 | //------------------------------------------------ | ||
98 | |||
99 | void | ||
100 | 19 | response:: | |
101 | set_impl( | ||
102 | http_proto::status sc, | ||
103 | unsigned short si, | ||
104 | core::string_view rs, | ||
105 | http_proto::version v) | ||
106 | { | ||
107 | // measure and resize | ||
108 | 19 | auto const vs = to_string(v); | |
109 | auto const n = | ||
110 | 19 | vs.size() + 1 + | |
111 | 19 | 3 + 1 + | |
112 | 19 | rs.size() + | |
113 | 19 | 2; | |
114 | |||
115 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
38 | detail::prefix_op op(*this, n); |
116 | 19 | auto dest = op.prefix_.data(); | |
117 | |||
118 | 19 | h_.version = v; | |
119 |
1/2✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
19 | vs.copy(dest, vs.size()); |
120 | 19 | dest += vs.size(); | |
121 | 19 | *dest++ = ' '; | |
122 | |||
123 | 19 | h_.res.status = sc; | |
124 | 19 | h_.res.status_int = si; | |
125 | 19 | dest[0] = '0' + ((h_.res.status_int / 100) % 10); | |
126 | 19 | dest[1] = '0' + ((h_.res.status_int / 10) % 10); | |
127 | 19 | dest[2] = '0' + ((h_.res.status_int / 1) % 10); | |
128 | 19 | dest[3] = ' '; | |
129 | 19 | dest += 4; | |
130 | |||
131 |
1/2✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
|
19 | rs.copy(dest, rs.size()); |
132 | 19 | dest += rs.size(); | |
133 | 19 | dest[0] = '\r'; | |
134 | 19 | dest[1] = '\n'; | |
135 | |||
136 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
19 | h_.on_start_line(); |
137 | 19 | } | |
138 | |||
139 | } // http_proto | ||
140 | } // boost | ||
141 |