src/rfc/detail/transfer_coding_rule.cpp

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