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