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