GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/response.cpp
Date: 2024-01-10 20:31:06
Exec Total Coverage
Lines: 10 60 16.7%
Functions: 2 8 25.0%
Branches: 0 14 0.0%

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