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