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