TLA Line data 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 HIT 34 : error_cat_type::
22 : name() const noexcept
23 : {
24 34 : return "boost.http";
25 : }
26 :
27 : std::string
28 111 : error_cat_type::
29 : message(int code) const
30 : {
31 111 : switch(static_cast<error>(code))
32 : {
33 3 : case error::expect_100_continue: return "expect 100 continue";
34 3 : case error::end_of_message: return "end of message";
35 3 : case error::end_of_stream: return "end of stream";
36 3 : case error::in_place_overflow: return "in-place overflow";
37 6 : case error::need_data: return "need data";
38 :
39 3 : case error::bad_connection: return "bad Connection";
40 3 : case error::bad_content_length: return "bad Content-Length";
41 3 : case error::bad_expect: return "bad Expect";
42 201 : case error::bad_field_name: return "bad field name";
43 9 : case error::bad_field_value: return "bad field value";
44 30 : case error::bad_field_smuggle: return "bad field smuggle";
45 3 : case error::bad_line_ending: return "bad line ending";
46 3 : case error::bad_list: return "bad list";
47 3 : case error::bad_method: return "bad method";
48 3 : case error::bad_number: return "bad number";
49 6 : case error::bad_payload: return "bad payload";
50 3 : case error::bad_version: return "bad version";
51 3 : case error::bad_reason: return "bad reason-phrase";
52 3 : case error::bad_request_target: return "bad request-target";
53 3 : case error::bad_status_code: return "bad status-code";
54 3 : case error::bad_status_line: return "bad status-line";
55 3 : case error::bad_transfer_encoding: return "bad Transfer-Encoding";
56 3 : case error::bad_upgrade: return "bad Upgrade";
57 :
58 3 : case error::body_too_large: return "body too large";
59 3 : case error::headers_limit: return "headers limit";
60 3 : case error::start_line_limit: return "start line limit";
61 3 : case error::field_size_limit: return "field size limit";
62 3 : case error::fields_limit: return "fields limit";
63 3 : case error::incomplete: return "incomplete";
64 :
65 3 : case error::numeric_overflow: return "numeric overflow";
66 3 : case error::multiple_content_length: return "multiple Content-Length";
67 3 : case error::buffer_overflow: return "buffer overflow";
68 MIS 0 : case error::unhandled_exception: return "unhandled exception";
69 0 : default:
70 0 : return "unknown";
71 : }
72 : }
73 :
74 : //-----------------------------------------------
75 :
76 : const char*
77 HIT 2 : condition_cat_type::
78 : name() const noexcept
79 : {
80 2 : return "boost.http";
81 : }
82 :
83 : std::string
84 2 : condition_cat_type::
85 : message(int code) const
86 : {
87 2 : switch(static_cast<condition>(code))
88 : {
89 1 : default:
90 2 : case condition::need_more_input: return "need more input";
91 3 : case condition::invalid_payload: return "invalid body octets received";
92 : }
93 : }
94 :
95 : bool
96 154836 : condition_cat_type::
97 : equivalent(
98 : std::error_code const& ec,
99 : int code) const noexcept
100 : {
101 154836 : switch(static_cast<condition>(code))
102 : {
103 10 : case condition::invalid_payload:
104 10 : return (ec == error::bad_payload);
105 154826 : case condition::need_more_input:
106 154826 : return ec == error::need_data;
107 MIS 0 : default:
108 0 : break;
109 : }
110 : return
111 0 : *this == ec.category() &&
112 0 : 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
|