GCC Code Coverage Report


Directory: libs/http_proto/
File: libs/http_proto/src/rfc/transfer_encoding_rule.cpp
Date: 2024-09-18 08:42:23
Exec Total Coverage
Lines: 49 56 87.5%
Functions: 2 2 100.0%
Branches: 20 26 76.9%

Line Branch Exec Source
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 "transfer_encoding_rule.hpp"
11
12 #include <boost/http_proto/rfc/token_rule.hpp>
13 #include <boost/http_proto/rfc/detail/rules.hpp>
14 #include <boost/url/grammar/ci_string.hpp>
15 #include <boost/url/grammar/parse.hpp>
16
17 namespace boost {
18 namespace http_proto {
19
20 //------------------------------------------------
21
22 namespace detail {
23
24 /*
25 tparams = *tparam
26 tparam = OWS ";" OWS token BWS "=" BWS ( token / quoted-string )
27 */
28
29 struct tparam_rule_t
30 {
31 using value_type =
32 transfer_encoding::param;
33
34 auto
35 49 parse(
36 char const*& it,
37 char const* end) const noexcept ->
38 system::result<value_type>
39 {
40 49 value_type t;
41 49 auto it0 = it;
42 // OWS
43 49 it = grammar::find_if_not(
44 it, end, ws);
45 // ";"
46
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 34 times.
49 if(it == end)
47 {
48 15 it = it0;
49 15 BOOST_HTTP_PROTO_RETURN_EC(
50 grammar::error::need_more);
51 }
52
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 14 times.
34 if(*it != ';')
53 {
54 20 it = it0;
55 20 BOOST_HTTP_PROTO_RETURN_EC(
56 grammar::error::mismatch);
57 }
58 14 ++it;
59 // OWS
60 14 it = grammar::find_if_not(
61 it, end, ws);
62 // token
63 {
64 14 auto rv = grammar::parse(
65 it, end, token_rule);
66
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if(! rv)
67 return rv.error();
68 14 t.key = *rv;
69 }
70 // BWS
71 14 it = grammar::find_if_not(
72 it, end, ws);
73 // "="
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(it == end)
75 {
76 it = it0;
77 BOOST_HTTP_PROTO_RETURN_EC(
78 grammar::error::need_more);
79 }
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if(*it != '=')
81 {
82 it = it0;
83 BOOST_HTTP_PROTO_RETURN_EC(
84 grammar::error::syntax);
85 }
86 14 ++it;
87 // BWS
88 14 it = grammar::find_if_not(
89 it, end, ws);
90 // quoted-token
91 {
92 14 auto rv = grammar::parse(
93 it, end, quoted_token_rule);
94
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if(! rv)
95 return rv.error();
96 14 t.value = *rv;
97 }
98 14 return t;
99 }
100 };
101
102 constexpr tparam_rule_t tparam_rule{};
103
104 //------------------------------------------------
105
106 auto
107 8617 transfer_encoding_rule_t::
108 parse(
109 char const*& it,
110 char const* end) const noexcept ->
111 system::result<value_type>
112 {
113 8617 value_type t;
114 {
115 // token
116 8617 auto rv = grammar::parse(
117 it, end, token_rule);
118
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8609 times.
8617 if(! rv)
119 8 return rv.error();
120 8609 t.str = *rv;
121
122 // These can't have tparams
123
2/2
✓ Branch 2 taken 8377 times.
✓ Branch 3 taken 232 times.
8609 if(grammar::ci_is_equal(
124 t.str, "chunked"))
125 {
126 8377 t.id = transfer_encoding::chunked;
127 8377 return t;
128 }
129
2/2
✓ Branch 2 taken 26 times.
✓ Branch 3 taken 206 times.
232 if(grammar::ci_is_equal(
130 t.str, "compress"))
131 {
132 26 t.id = transfer_encoding::compress;
133 26 return t;
134 }
135
2/2
✓ Branch 2 taken 79 times.
✓ Branch 3 taken 127 times.
206 if(grammar::ci_is_equal(
136 t.str, "deflate"))
137 {
138 79 t.id = transfer_encoding::deflate;
139 79 return t;
140 }
141
2/2
✓ Branch 2 taken 92 times.
✓ Branch 3 taken 35 times.
127 if(grammar::ci_is_equal(
142 t.str, "gzip"))
143 {
144 92 t.id = transfer_encoding::gzip;
145 92 return t;
146 }
147 }
148 // *( OWS ";" OWS token BWS "=" BWS ( token / quoted-string )
149 {
150 auto rv = grammar::parse(it, end,
151 35 grammar::range_rule(
152 35 detail::tparam_rule));
153
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
35 if(! rv)
154 return rv.error();
155 35 t.params = std::move(*rv);
156
1/2
✓ Branch 1 taken 35 times.
✗ Branch 2 not taken.
35 }
157 35 return t;
158 8617 }
159 } // detail
160
161
162 } // http_proto
163 } // boost
164