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