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