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