GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/status.cpp
Date: 2024-01-12 19:51:55
Exec Total Coverage
Lines: 77 88 87.5%
Functions: 4 5 80.0%
Branches: 66 71 93.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/status.hpp>
11 #include <boost/throw_exception.hpp>
12 #include <ostream>
13
14 namespace boost {
15 namespace http_proto {
16
17 status
18 599 int_to_status(unsigned v)
19 {
20
1/2
✓ Branch 0 taken 599 times.
✗ Branch 1 not taken.
599 switch(static_cast<status>(v))
21 {
22 // 1xx
23 599 case status::continue_:
24 case status::switching_protocols:
25 case status::processing:
26 BOOST_FALLTHROUGH;
27
28 // 2xx
29 case status::ok:
30 case status::created:
31 case status::accepted:
32 case status::non_authoritative_information:
33 case status::no_content:
34 case status::reset_content:
35 case status::partial_content:
36 case status::multi_status:
37 case status::already_reported:
38 case status::im_used:
39 BOOST_FALLTHROUGH;
40
41 // 3xx
42 case status::multiple_choices:
43 case status::moved_permanently:
44 case status::found:
45 case status::see_other:
46 case status::not_modified:
47 case status::use_proxy:
48 case status::temporary_redirect:
49 case status::permanent_redirect:
50 BOOST_FALLTHROUGH;
51
52 // 4xx
53 case status::bad_request:
54 case status::unauthorized:
55 case status::payment_required:
56 case status::forbidden:
57 case status::not_found:
58 case status::method_not_allowed:
59 case status::not_acceptable:
60 case status::proxy_authentication_required:
61 case status::request_timeout:
62 case status::conflict:
63 case status::gone:
64 case status::length_required:
65 case status::precondition_failed:
66 case status::payload_too_large:
67 case status::uri_too_long:
68 case status::unsupported_media_type:
69 case status::range_not_satisfiable:
70 case status::expectation_failed:
71 case status::misdirected_request:
72 case status::unprocessable_entity:
73 case status::locked:
74 case status::failed_dependency:
75 case status::upgrade_required:
76 case status::precondition_required:
77 case status::too_many_requests:
78 case status::request_header_fields_too_large:
79 case status::connection_closed_without_response:
80 case status::unavailable_for_legal_reasons:
81 case status::client_closed_request:
82 BOOST_FALLTHROUGH;
83
84 // 5xx
85 case status::internal_server_error:
86 case status::not_implemented:
87 case status::bad_gateway:
88 case status::service_unavailable:
89 case status::gateway_timeout:
90 case status::http_version_not_supported:
91 case status::variant_also_negotiates:
92 case status::insufficient_storage:
93 case status::loop_detected:
94 case status::not_extended:
95 case status::network_authentication_required:
96 case status::network_connect_timeout_error:
97 599 return static_cast<status>(v);
98
99 default:
100 break;
101 }
102 return status::unknown;
103 }
104
105 status_class
106 126 to_status_class(unsigned v)
107 {
108
6/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 58 times.
✓ Branch 4 taken 24 times.
✓ Branch 5 taken 2 times.
126 switch(v / 100)
109 {
110 6 case 1: return status_class::informational;
111 20 case 2: return status_class::successful;
112 16 case 3: return status_class::redirection;
113 58 case 4: return status_class::client_error;
114 24 case 5: return status_class::server_error;
115 2 default:
116 2 break;
117 }
118 2 return status_class::unknown;
119 }
120
121 status_class
122 63 to_status_class(status v)
123 {
124 63 return to_status_class(static_cast<int>(v));
125 }
126
127 core::string_view
128 59 obsolete_reason(
129 status v)
130 {
131
59/63
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 1 times.
✓ Branch 28 taken 1 times.
✓ Branch 29 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 1 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 34 taken 1 times.
✓ Branch 35 taken 1 times.
✓ Branch 36 taken 1 times.
✓ Branch 37 taken 1 times.
✓ Branch 38 taken 1 times.
✓ Branch 39 taken 1 times.
✓ Branch 40 taken 1 times.
✓ Branch 41 taken 1 times.
✓ Branch 42 taken 1 times.
✓ Branch 43 taken 1 times.
✓ Branch 44 taken 1 times.
✓ Branch 45 taken 1 times.
✓ Branch 46 taken 1 times.
✗ Branch 47 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 50 taken 1 times.
✓ Branch 51 taken 1 times.
✓ Branch 52 taken 1 times.
✓ Branch 53 taken 1 times.
✓ Branch 54 taken 1 times.
✓ Branch 55 taken 1 times.
✓ Branch 56 taken 1 times.
✓ Branch 57 taken 1 times.
✓ Branch 58 taken 1 times.
✓ Branch 59 taken 1 times.
✓ Branch 60 taken 1 times.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
59 switch(static_cast<status>(v))
132 {
133 // 1xx
134 1 case status::continue_: return "Continue";
135 1 case status::switching_protocols: return "Switching Protocols";
136 1 case status::processing: return "Processing";
137
138 // 2xx
139 1 case status::ok: return "OK";
140 1 case status::created: return "Created";
141 1 case status::accepted: return "Accepted";
142 1 case status::non_authoritative_information: return "Non-Authoritative Information";
143 1 case status::no_content: return "No Content";
144 1 case status::reset_content: return "Reset Content";
145 1 case status::partial_content: return "Partial Content";
146 1 case status::multi_status: return "Multi-Status";
147 1 case status::already_reported: return "Already Reported";
148 1 case status::im_used: return "IM Used";
149
150 // 3xx
151 1 case status::multiple_choices: return "Multiple Choices";
152 1 case status::moved_permanently: return "Moved Permanently";
153 1 case status::found: return "Found";
154 1 case status::see_other: return "See Other";
155 1 case status::not_modified: return "Not Modified";
156 1 case status::use_proxy: return "Use Proxy";
157 1 case status::temporary_redirect: return "Temporary Redirect";
158 1 case status::permanent_redirect: return "Permanent Redirect";
159
160 // 4xx
161 1 case status::bad_request: return "Bad Request";
162 1 case status::unauthorized: return "Unauthorized";
163 1 case status::payment_required: return "Payment Required";
164 1 case status::forbidden: return "Forbidden";
165 1 case status::not_found: return "Not Found";
166 1 case status::method_not_allowed: return "Method Not Allowed";
167 1 case status::not_acceptable: return "Not Acceptable";
168 1 case status::proxy_authentication_required: return "Proxy Authentication Required";
169 1 case status::request_timeout: return "Request Timeout";
170 1 case status::conflict: return "Conflict";
171 1 case status::gone: return "Gone";
172 1 case status::length_required: return "Length Required";
173 1 case status::precondition_failed: return "Precondition Failed";
174 1 case status::payload_too_large: return "Payload Too Large";
175 1 case status::uri_too_long: return "URI Too Long";
176 1 case status::unsupported_media_type: return "Unsupported Media Type";
177 1 case status::range_not_satisfiable: return "Range Not Satisfiable";
178 1 case status::expectation_failed: return "Expectation Failed";
179 1 case status::misdirected_request: return "Misdirected Request";
180 1 case status::unprocessable_entity: return "Unprocessable Entity";
181 1 case status::locked: return "Locked";
182 1 case status::failed_dependency: return "Failed Dependency";
183 1 case status::upgrade_required: return "Upgrade Required";
184 1 case status::precondition_required: return "Precondition Required";
185 1 case status::too_many_requests: return "Too Many Requests";
186 1 case status::request_header_fields_too_large: return "Request Header Fields Too Large";
187 case status::connection_closed_without_response: return "Connection Closed Without Response";
188 1 case status::unavailable_for_legal_reasons: return "Unavailable For Legal Reasons";
189 case status::client_closed_request: return "Client Closed Request";
190 // 5xx
191 1 case status::internal_server_error: return "Internal Server Error";
192 1 case status::not_implemented: return "Not Implemented";
193 1 case status::bad_gateway: return "Bad Gateway";
194 1 case status::service_unavailable: return "Service Unavailable";
195 1 case status::gateway_timeout: return "Gateway Timeout";
196 1 case status::http_version_not_supported: return "HTTP Version Not Supported";
197 1 case status::variant_also_negotiates: return "Variant Also Negotiates";
198 1 case status::insufficient_storage: return "Insufficient Storage";
199 1 case status::loop_detected: return "Loop Detected";
200 1 case status::not_extended: return "Not Extended";
201 1 case status::network_authentication_required: return "Network Authentication Required";
202 case status::network_connect_timeout_error: return "Network Connect Timeout Error";
203
204 default:
205 break;
206 }
207 return "<unknown-status>";
208 }
209
210 std::ostream&
211 operator<<(std::ostream& os, status v)
212 {
213 return os << obsolete_reason(v);
214 }
215
216 } // http_proto
217 } // boost
218