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