src/error.cpp
91.7% Lines (55/0/60)
100.0% List of functions (5/0/5)
Functions (5)
Function
Calls
Lines
Blocks
boost::http::detail::error_cat_type::name() const
:21
33x
100.0%
100.0%
boost::http::detail::error_cat_type::message[abi:cxx11](int) const
:28
110x
91.9%
59.0%
boost::http::detail::condition_cat_type::name() const
:77
2x
100.0%
100.0%
boost::http::detail::condition_cat_type::message[abi:cxx11](int) const
:84
2x
100.0%
72.0%
boost::http::detail::condition_cat_type::equivalent(std::error_code const&, int) const
:96
154843x
85.7%
84.0%
| Line | TLA | Hits | 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 | ||
| 8 | // | ||
| 9 | |||
| 10 | #include <boost/http/error.hpp> | ||
| 11 | #include <boost/url/grammar/error.hpp> | ||
| 12 | #include <boost/assert.hpp> | ||
| 13 | #include <cstring> | ||
| 14 | |||
| 15 | namespace boost { | ||
| 16 | namespace http { | ||
| 17 | |||
| 18 | namespace detail { | ||
| 19 | |||
| 20 | const char* | ||
| 21 | 33x | error_cat_type:: | |
| 22 | name() const noexcept | ||
| 23 | { | ||
| 24 | 33x | return "boost.http"; | |
| 25 | } | ||
| 26 | |||
| 27 | std::string | ||
| 28 | 110x | error_cat_type:: | |
| 29 | message(int code) const | ||
| 30 | { | ||
| 31 | 110x | switch(static_cast<error>(code)) | |
| 32 | { | ||
| 33 | 3x | case error::expect_100_continue: return "expect 100 continue"; | |
| 34 | 3x | case error::end_of_message: return "end of message"; | |
| 35 | 3x | case error::end_of_stream: return "end of stream"; | |
| 36 | 3x | case error::in_place_overflow: return "in-place overflow"; | |
| 37 | 3x | case error::need_data: return "need data"; | |
| 38 | |||
| 39 | 3x | case error::bad_connection: return "bad Connection"; | |
| 40 | 3x | case error::bad_content_length: return "bad Content-Length"; | |
| 41 | 3x | case error::bad_expect: return "bad Expect"; | |
| 42 | 201x | case error::bad_field_name: return "bad field name"; | |
| 43 | 9x | case error::bad_field_value: return "bad field value"; | |
| 44 | 30x | case error::bad_field_smuggle: return "bad field smuggle"; | |
| 45 | 3x | case error::bad_line_ending: return "bad line ending"; | |
| 46 | 3x | case error::bad_list: return "bad list"; | |
| 47 | 3x | case error::bad_method: return "bad method"; | |
| 48 | 3x | case error::bad_number: return "bad number"; | |
| 49 | 6x | case error::bad_payload: return "bad payload"; | |
| 50 | 3x | case error::bad_version: return "bad version"; | |
| 51 | 3x | case error::bad_reason: return "bad reason-phrase"; | |
| 52 | 3x | case error::bad_request_target: return "bad request-target"; | |
| 53 | 3x | case error::bad_status_code: return "bad status-code"; | |
| 54 | 3x | case error::bad_status_line: return "bad status-line"; | |
| 55 | 3x | case error::bad_transfer_encoding: return "bad Transfer-Encoding"; | |
| 56 | 3x | case error::bad_upgrade: return "bad Upgrade"; | |
| 57 | |||
| 58 | 3x | case error::body_too_large: return "body too large"; | |
| 59 | 3x | case error::headers_limit: return "headers limit"; | |
| 60 | 3x | case error::start_line_limit: return "start line limit"; | |
| 61 | 3x | case error::field_size_limit: return "field size limit"; | |
| 62 | 3x | case error::fields_limit: return "fields limit"; | |
| 63 | 3x | case error::incomplete: return "incomplete"; | |
| 64 | |||
| 65 | 3x | case error::numeric_overflow: return "numeric overflow"; | |
| 66 | 3x | case error::multiple_content_length: return "multiple Content-Length"; | |
| 67 | 3x | case error::buffer_overflow: return "buffer overflow"; | |
| 68 | ✗ | case error::unhandled_exception: return "unhandled exception"; | |
| 69 | ✗ | default: | |
| 70 | ✗ | return "unknown"; | |
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | //----------------------------------------------- | ||
| 75 | |||
| 76 | const char* | ||
| 77 | 2x | condition_cat_type:: | |
| 78 | name() const noexcept | ||
| 79 | { | ||
| 80 | 2x | return "boost.http"; | |
| 81 | } | ||
| 82 | |||
| 83 | std::string | ||
| 84 | 2x | condition_cat_type:: | |
| 85 | message(int code) const | ||
| 86 | { | ||
| 87 | 2x | switch(static_cast<condition>(code)) | |
| 88 | { | ||
| 89 | 1x | default: | |
| 90 | 2x | case condition::need_more_input: return "need more input"; | |
| 91 | 3x | case condition::invalid_payload: return "invalid body octets received"; | |
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | bool | ||
| 96 | 154843x | condition_cat_type:: | |
| 97 | equivalent( | ||
| 98 | std::error_code const& ec, | ||
| 99 | int code) const noexcept | ||
| 100 | { | ||
| 101 | 154843x | switch(static_cast<condition>(code)) | |
| 102 | { | ||
| 103 | 10x | case condition::invalid_payload: | |
| 104 | 10x | return (ec == error::bad_payload); | |
| 105 | |||
| 106 | 154833x | case condition::need_more_input: | |
| 107 | 154833x | if( ec == system::error_code( | |
| 108 | 231741x | urls::grammar::error::need_more) || | |
| 109 | 231741x | ec == error::need_data ) | |
| 110 | 142250x | return true; | |
| 111 | 12583x | break; | |
| 112 | |||
| 113 | ✗ | default: | |
| 114 | ✗ | break; | |
| 115 | } | ||
| 116 | return | ||
| 117 | 12583x | *this == ec.category() && | |
| 118 | 12583x | ec.value() == code; | |
| 119 | } | ||
| 120 | |||
| 121 | //----------------------------------------------- | ||
| 122 | |||
| 123 | // msvc 14.0 has a bug that warns about inability | ||
| 124 | // to use constexpr construction here, even though | ||
| 125 | // there's no constexpr construction | ||
| 126 | #if defined(_MSC_VER) && _MSC_VER <= 1900 | ||
| 127 | # pragma warning( push ) | ||
| 128 | # pragma warning( disable : 4592 ) | ||
| 129 | #endif | ||
| 130 | |||
| 131 | #if defined(__cpp_constinit) && __cpp_constinit >= 201907L | ||
| 132 | constinit error_cat_type error_cat; | ||
| 133 | constinit condition_cat_type condition_cat; | ||
| 134 | #else | ||
| 135 | error_cat_type error_cat; | ||
| 136 | condition_cat_type condition_cat; | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #if defined(_MSC_VER) && _MSC_VER <= 1900 | ||
| 140 | # pragma warning( pop ) | ||
| 141 | #endif | ||
| 142 | |||
| 143 | } // detail | ||
| 144 | |||
| 145 | } // http | ||
| 146 | } // boost | ||
| 147 |