libs/http/src/error.cpp

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