LCOV - code coverage report
Current view: top level - libs/http_proto/src/error.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 93.5 % 62 58
Test Date: 2024-08-25 18:42:41 Functions: 100.0 % 7 7

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

Generated by: LCOV version 2.1