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