LCOV - code coverage report
Current view: top level - src/rfc/detail - transfer_coding_rule.cpp (source / functions) Coverage Total Hit Missed
Test: coverage_remapped.info Lines: 88.3 % 60 53 7
Test Date: 2026-06-13 19:44:58 Functions: 100.0 % 2 2

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com)
       3                 : // Copyright (c) 2025 Mohammad Nejati
       4                 : //
       5                 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       6                 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       7                 : //
       8                 : // Official repository: https://github.com/cppalliance/http
       9                 : //
      10                 : 
      11                 : #include "src/rfc/detail/transfer_coding_rule.hpp"
      12                 : 
      13                 : #include <boost/http/rfc/detail/ws.hpp>
      14                 : #include <boost/http/rfc/quoted_token_rule.hpp>
      15                 : #include <boost/http/rfc/token_rule.hpp>
      16                 : #include <boost/url/grammar/ci_string.hpp>
      17                 : #include <boost/url/grammar/parse.hpp>
      18                 : 
      19                 : namespace boost {
      20                 : namespace http {
      21                 : namespace detail {
      22                 : 
      23                 : auto
      24 HIT          43 : transfer_parameter_rule_t::parse(
      25                 :     char const*& it,
      26                 :     char const* end) const noexcept ->
      27                 :         system::result<value_type>
      28                 : {
      29              43 :     value_type t;
      30              43 :     auto it0 = it;
      31                 :     // OWS
      32              43 :     it = grammar::find_if_not(
      33                 :         it, end, ws);
      34                 :     // ";"
      35              43 :     if(it == end)
      36                 :     {
      37              13 :         it = it0;
      38              13 :         BOOST_HTTP_RETURN_EC(
      39                 :             grammar::error::need_more);
      40                 :     }
      41              30 :     if(*it != ';')
      42                 :     {
      43              16 :         it = it0;
      44              16 :         BOOST_HTTP_RETURN_EC(
      45                 :             grammar::error::mismatch);
      46                 :     }
      47              14 :     ++it;
      48                 :     // OWS
      49              14 :     it = grammar::find_if_not(
      50                 :         it, end, ws);
      51                 :     // token
      52                 :     {
      53              14 :         auto rv = grammar::parse(
      54                 :             it, end, token_rule);
      55              14 :         if(! rv)
      56 MIS           0 :             return rv.error();
      57 HIT          14 :         t.name = *rv;
      58                 :     }
      59                 :     // BWS
      60              14 :     it = grammar::find_if_not(
      61                 :         it, end, ws);
      62                 :     // "="
      63              14 :     if(it == end)
      64                 :     {
      65 MIS           0 :         it = it0;
      66               0 :         BOOST_HTTP_RETURN_EC(
      67                 :             grammar::error::need_more);
      68                 :     }
      69 HIT          14 :     if(*it != '=')
      70                 :     {
      71 MIS           0 :         it = it0;
      72               0 :         BOOST_HTTP_RETURN_EC(
      73                 :             grammar::error::syntax);
      74                 :     }
      75 HIT          14 :     ++it;
      76                 :     // BWS
      77              14 :     it = grammar::find_if_not(
      78                 :         it, end, ws);
      79                 :     // quoted-token
      80                 :     {
      81              14 :         auto rv = grammar::parse(
      82                 :             it, end, quoted_token_rule);
      83              14 :         if(! rv)
      84 MIS           0 :             return rv.error();
      85 HIT          14 :         t.value = *rv;
      86                 :     }
      87              14 :     return t;
      88                 : }
      89                 : 
      90                 : //------------------------------------------------
      91                 : 
      92                 : auto
      93            8881 : transfer_coding_rule_t::
      94                 : parse(
      95                 :     char const*& it,
      96                 :     char const* end) const noexcept ->
      97                 :         system::result<value_type>
      98                 : {
      99            8881 :     value_type t;
     100                 :     {
     101                 :         // token
     102            8881 :         auto rv = grammar::parse(
     103                 :             it, end, token_rule);
     104            8881 :         if(! rv)
     105               8 :             return rv.error();
     106                 : 
     107                 :         // These can't have transfer-parameter
     108           17746 :         if(grammar::ci_is_equal(
     109            8873 :             *rv, "chunked"))
     110                 :         {
     111            8805 :             t.id = coding::chunked;
     112            8805 :             return t;
     113                 :         }
     114             136 :         if(grammar::ci_is_equal(
     115              68 :             *rv, "compress"))
     116                 :         {
     117              20 :             t.id = coding::compress;
     118              20 :             return t;
     119                 :         }
     120              96 :         if(grammar::ci_is_equal(
     121              48 :             *rv, "deflate"))
     122                 :         {
     123               7 :             t.id = coding::deflate;
     124               7 :             return t;
     125                 :         }
     126              82 :         if(grammar::ci_is_equal(
     127              41 :             *rv, "gzip"))
     128                 :         {
     129              12 :             t.id = coding::gzip;
     130              12 :             return t;
     131                 :         }
     132                 : 
     133              29 :         t.extension.token = *rv;
     134                 :     }
     135                 :     // transfer-extension = token *( OWS ";" OWS transfer-parameter )
     136                 :     {
     137                 :         auto rv = grammar::parse(it, end,
     138              29 :             grammar::range_rule(
     139              29 :                 detail::transfer_parameter_rule));
     140              29 :         if(! rv)
     141 MIS           0 :             return rv.error();
     142 HIT          29 :         t.extension.params = std::move(*rv);
     143              29 :     }
     144              29 :     return t;
     145            8881 : }
     146                 : 
     147                 : } // detail
     148                 : } // http
     149                 : } // boost
        

Generated by: LCOV version 2.3