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 118 : get_error_cat() noexcept 25 : { 26 : struct codes : error_category 27 : { 28 5 : codes() noexcept 29 5 : : error_category( 30 5 : 0x3663257e7585fbfd) 31 : { 32 5 : } 33 : 34 : const char* 35 28 : name() const noexcept override 36 : { 37 28 : return "boost.http.proto"; 38 : } 39 : 40 : std::string 41 28 : message(int ev) const override 42 : { 43 28 : switch(static_cast<error>(ev)) 44 : { 45 1 : case error::expect_100_continue: return "expect continue"; 46 1 : case error::end_of_message: return "end of message"; 47 1 : case error::end_of_stream: return "end of stream"; 48 1 : case error::need_data: return "need data"; 49 : 50 1 : case error::bad_connection: return "bad Connection"; 51 1 : case error::bad_content_length: return "bad Content-Length"; 52 1 : case error::bad_expect: return "bad Expect"; 53 1 : case error::bad_field_name: return "bad field name"; 54 1 : case error::bad_field_value: return "bad field value"; 55 1 : case error::bad_line_ending: return "bad line ending"; 56 1 : case error::bad_list: return "bad list"; 57 1 : case error::bad_method: return "bad method"; 58 1 : case error::bad_number: return "bad number"; 59 1 : case error::bad_version: return "bad version"; 60 1 : case error::bad_reason: return "bad reason-phrase"; 61 1 : case error::bad_request_target: return "bad request-target"; 62 1 : case error::bad_status_code: return "bad status-code"; 63 1 : case error::bad_status_line: return "bad status-line"; 64 1 : case error::bad_transfer_encoding: return "bad Transfer-Encoding"; 65 1 : case error::bad_upgrade: return "bad Upgrade"; 66 : 67 1 : case error::body_too_large: return "body too large"; 68 1 : case error::headers_limit: return "headers limit"; 69 1 : case error::start_line_limit: return "start line limit"; 70 1 : case error::field_size_limit: return "field size limit"; 71 1 : case error::fields_limit: return "fields limit"; 72 1 : case error::incomplete: return "incomplete"; 73 : 74 1 : case error::numeric_overflow: return "numeric overflow"; 75 1 : case error::multiple_content_length: return "multiple Content-Length"; 76 0 : default: 77 0 : return "unknown"; 78 : } 79 : } 80 : }; 81 118 : static codes const t{}; 82 118 : return t; 83 : } 84 : 85 : } // detail 86 : 87 : error_code 88 118 : make_error_code( 89 : error ev) noexcept 90 : { 91 : return error_code{static_cast< 92 : std::underlying_type< 93 : error>::type>(ev), 94 118 : detail::get_error_cat()}; 95 : } 96 : 97 : } // http_proto 98 : } // boost 99 : 100 : #endif