src/error.cpp

87.5% Lines (49/0/56) 100.0% List of functions (5/0/5)
error.cpp
f(x) Functions (5)
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 34x error_cat_type::
22 name() const noexcept
23 {
24 34x return "boost.http";
25 }
26
27 std::string
28 111x error_cat_type::
29 message(int code) const
30 {
31 111x 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 6x 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 154836x condition_cat_type::
97 equivalent(
98 std::error_code const& ec,
99 int code) const noexcept
100 {
101 154836x switch(static_cast<condition>(code))
102 {
103 10x case condition::invalid_payload:
104 10x return (ec == error::bad_payload);
105 154826x case condition::need_more_input:
106 154826x return ec == error::need_data;
107 default:
108 break;
109 }
110 return
111 *this == ec.category() &&
112 ec.value() == code;
113 }
114
115 //-----------------------------------------------
116
117 // msvc 14.0 has a bug that warns about inability
118 // to use constexpr construction here, even though
119 // there's no constexpr construction
120 #if defined(_MSC_VER) && _MSC_VER <= 1900
121 # pragma warning( push )
122 # pragma warning( disable : 4592 )
123 #endif
124
125 #if defined(__cpp_constinit) && __cpp_constinit >= 201907L
126 constinit error_cat_type error_cat;
127 constinit condition_cat_type condition_cat;
128 #else
129 error_cat_type error_cat;
130 condition_cat_type condition_cat;
131 #endif
132
133 #if defined(_MSC_VER) && _MSC_VER <= 1900
134 # pragma warning( pop )
135 #endif
136
137 } // detail
138
139 } // http
140 } // boost
141