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