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