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