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 return grammar::error::need_more;
39 - grammar::error::need_more);  
40   } 39   }
HITCBC 41   30 if(*it != ';') 40   30 if(*it != ';')
42   { 41   {
HITCBC 43   16 it = it0; 42   16 it = it0;
HITCBC 44 - 16 BOOST_HTTP_RETURN_EC( 43 + 16 return grammar::error::mismatch;
45 - grammar::error::mismatch);  
46   } 44   }
HITCBC 47   14 ++it; 45   14 ++it;
48   // OWS 46   // OWS
HITCBC 49   14 it = grammar::find_if_not( 47   14 it = grammar::find_if_not(
50   it, end, ws); 48   it, end, ws);
51   // token 49   // token
52   { 50   {
HITCBC 53   14 auto rv = grammar::parse( 51   14 auto rv = grammar::parse(
54   it, end, token_rule); 52   it, end, token_rule);
HITCBC 55   14 if(! rv) 53   14 if(! rv)
MISUBC 56   return rv.error(); 54   return rv.error();
HITCBC 57   14 t.name = *rv; 55   14 t.name = *rv;
58   } 56   }
59   // BWS 57   // BWS
HITCBC 60   14 it = grammar::find_if_not( 58   14 it = grammar::find_if_not(
61   it, end, ws); 59   it, end, ws);
62   // "=" 60   // "="
HITCBC 63   14 if(it == end) 61   14 if(it == end)
64   { 62   {
MISUBC 65   it = it0; 63   it = it0;
MISUBC 66 - BOOST_HTTP_RETURN_EC( 64 + return grammar::error::need_more;
67 - grammar::error::need_more);  
68   } 65   }
HITCBC 69   14 if(*it != '=') 66   14 if(*it != '=')
70   { 67   {
MISUBC 71   it = it0; 68   it = it0;
MISUBC 72 - BOOST_HTTP_RETURN_EC( 69 + return grammar::error::syntax;
73 - grammar::error::syntax);  
74   } 70   }
HITCBC 75   14 ++it; 71   14 ++it;
76   // BWS 72   // BWS
HITCBC 77   14 it = grammar::find_if_not( 73   14 it = grammar::find_if_not(
78   it, end, ws); 74   it, end, ws);
79   // quoted-token 75   // quoted-token
80   { 76   {
HITCBC 81   14 auto rv = grammar::parse( 77   14 auto rv = grammar::parse(
82   it, end, quoted_token_rule); 78   it, end, quoted_token_rule);
HITCBC 83   14 if(! rv) 79   14 if(! rv)
MISUBC 84   return rv.error(); 80   return rv.error();
HITCBC 85   14 t.value = *rv; 81   14 t.value = *rv;
86   } 82   }
HITCBC 87   14 return t; 83   14 return t;
88   } 84   }
89   85  
90   //------------------------------------------------ 86   //------------------------------------------------
91   87  
92   auto 88   auto
HITCBC 93   8881 transfer_coding_rule_t:: 89   8881 transfer_coding_rule_t::
94   parse( 90   parse(
95   char const*& it, 91   char const*& it,
96   char const* end) const noexcept -> 92   char const* end) const noexcept ->
97   system::result<value_type> 93   system::result<value_type>
98   { 94   {
HITCBC 99   8881 value_type t; 95   8881 value_type t;
100   { 96   {
101   // token 97   // token
HITCBC 102   8881 auto rv = grammar::parse( 98   8881 auto rv = grammar::parse(
103   it, end, token_rule); 99   it, end, token_rule);
HITCBC 104   8881 if(! rv) 100   8881 if(! rv)
HITCBC 105   8 return rv.error(); 101   8 return rv.error();
106   102  
107   // These can't have transfer-parameter 103   // These can't have transfer-parameter
HITCBC 108   17746 if(grammar::ci_is_equal( 104   17746 if(grammar::ci_is_equal(
HITCBC 109   8873 *rv, "chunked")) 105   8873 *rv, "chunked"))
110   { 106   {
HITCBC 111   8805 t.id = coding::chunked; 107   8805 t.id = coding::chunked;
HITCBC 112   8805 return t; 108   8805 return t;
113   } 109   }
HITCBC 114   136 if(grammar::ci_is_equal( 110   136 if(grammar::ci_is_equal(
HITCBC 115   68 *rv, "compress")) 111   68 *rv, "compress"))
116   { 112   {
HITCBC 117   20 t.id = coding::compress; 113   20 t.id = coding::compress;
HITCBC 118   20 return t; 114   20 return t;
119   } 115   }
HITCBC 120   96 if(grammar::ci_is_equal( 116   96 if(grammar::ci_is_equal(
HITCBC 121   48 *rv, "deflate")) 117   48 *rv, "deflate"))
122   { 118   {
HITCBC 123   7 t.id = coding::deflate; 119   7 t.id = coding::deflate;
HITCBC 124   7 return t; 120   7 return t;
125   } 121   }
HITCBC 126   82 if(grammar::ci_is_equal( 122   82 if(grammar::ci_is_equal(
HITCBC 127   41 *rv, "gzip")) 123   41 *rv, "gzip"))
128   { 124   {
HITCBC 129   12 t.id = coding::gzip; 125   12 t.id = coding::gzip;
HITCBC 130   12 return t; 126   12 return t;
131   } 127   }
132   128  
HITCBC 133   29 t.extension.token = *rv; 129   29 t.extension.token = *rv;
134   } 130   }
135   // transfer-extension = token *( OWS ";" OWS transfer-parameter ) 131   // transfer-extension = token *( OWS ";" OWS transfer-parameter )
136   { 132   {
137   auto rv = grammar::parse(it, end, 133   auto rv = grammar::parse(it, end,
HITCBC 138   29 grammar::range_rule( 134   29 grammar::range_rule(
HITCBC 139   29 detail::transfer_parameter_rule)); 135   29 detail::transfer_parameter_rule));
HITCBC 140   29 if(! rv) 136   29 if(! rv)
MISUBC 141   return rv.error(); 137   return rv.error();
HITCBC 142   29 t.extension.params = std::move(*rv); 138   29 t.extension.params = std::move(*rv);
HITCBC 143   29 } 139   29 }
HITCBC 144   29 return t; 140   29 return t;
HITCBC 145   8881 } 141   8881 }
146   142  
147   } // detail 143   } // detail
148   } // http 144   } // http
149   } // boost 145   } // boost