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