Line data Source code
1 : // 2 : // Copyright (c) 2021 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/CPPAlliance/http_proto 8 : // 9 : 10 : #ifndef BOOST_HTTP_PROTO_IMPL_ERROR_IPP 11 : #define BOOST_HTTP_PROTO_IMPL_ERROR_IPP 12 : 13 : #include <boost/http_proto/error.hpp> 14 : #include <boost/assert.hpp> 15 : #include <type_traits> 16 : 17 : namespace boost { 18 : namespace http_proto { 19 : 20 : namespace detail { 21 : 22 : static 23 : error_category const& 24 108 : get_error_cat() noexcept 25 : { 26 : struct codes : error_category 27 : { 28 4 : codes() noexcept 29 4 : : error_category( 30 4 : 0x3663257e7585fbfd) 31 : { 32 4 : } 33 : 34 : const char* 35 25 : name() const noexcept override 36 : { 37 25 : return "boost.http.proto"; 38 : } 39 : 40 : std::string 41 25 : message(int ev) const override 42 : { 43 25 : switch(static_cast<error>(ev)) 44 : { 45 1 : case error::end_of_message: return "end of message"; 46 1 : case error::end_of_stream: return "end of stream"; 47 1 : case error::bad_connection: return "bad Connection"; 48 1 : case error::bad_content_length: return "bad Content-Length"; 49 1 : case error::bad_expect: return "bad Expect"; 50 1 : case error::bad_field_name: return "bad field name"; 51 1 : case error::bad_field_value: return "bad field value"; 52 1 : case error::bad_line_ending: return "bad line ending"; 53 1 : case error::bad_list: return "bad list"; 54 1 : case error::bad_method: return "bad method"; 55 1 : case error::bad_number: return "bad number"; 56 1 : case error::bad_version: return "bad version"; 57 1 : case error::bad_reason: return "bad reason-phrase"; 58 1 : case error::bad_request_target: return "bad request-target"; 59 1 : case error::bad_status_code: return "bad status-code"; 60 1 : case error::bad_status_line: return "bad status-line"; 61 1 : case error::bad_transfer_encoding: return "bad Transfer-Encoding"; 62 1 : case error::bad_upgrade: return "bad Upgrade"; 63 1 : case error::syntax: return "syntax error"; 64 : 65 1 : case error::body_too_large: return "body too large"; 66 1 : case error::field_too_large: return "field too large"; 67 1 : case error::header_too_large: return "header too large"; 68 1 : case error::too_many_fields: return "too many fields"; 69 1 : case error::numeric_overflow: return "numeric overflow"; 70 : 71 1 : case error::multiple_content_length: return "multiple Content-Length"; 72 0 : default: 73 0 : return "unknown"; 74 : } 75 : } 76 : }; 77 108 : static codes const t{}; 78 108 : return t; 79 : } 80 : 81 : } // detail 82 : 83 : error_code 84 108 : make_error_code( 85 : error ev) noexcept 86 : { 87 : return error_code{static_cast< 88 : std::underlying_type< 89 : error>::type>(ev), 90 108 : detail::get_error_cat()}; 91 : } 92 : 93 : } // http_proto 94 : } // boost 95 : 96 : #endif