GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/impl/response.ipp
Date: 2023-02-02 18:17:22
Exec Total Coverage
Lines: 8 53 15.1%
Functions: 2 8 25.0%
Branches: 0 12 0.0%

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