2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
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)
7 // Official repository: https://github.com/boostorg/beast
10 #ifndef BOOST_BEAST_HTTP_RFC7230_HPP
11 #define BOOST_BEAST_HTTP_RFC7230_HPP
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/http/detail/rfc7230.hpp>
15 #include <boost/beast/http/detail/basic_parsed_list.hpp>
21 /** A list of parameters in an HTTP extension field value.
23 This container allows iteration of the parameter list in an HTTP
24 extension. The parameter list is a series of name/value pairs
25 with each pair starting with a semicolon. The value is optional.
27 If a parsing error is encountered while iterating the string,
28 the behavior of the container will be as if a string containing
29 only characters up to but excluding the first invalid character
30 was used to construct the list.
34 param-list = *( OWS ";" OWS param )
35 param = token OWS [ "=" OWS ( token / quoted-string ) ]
38 To use this class, construct with the string to be parsed and
39 then use @ref begin and @ref end, or range-for to iterate each
44 for(auto const& param : param_list{";level=9;no_context_takeover;bits=15"})
46 std::cout << ";" << param.first;
47 if(! param.second.empty())
48 std::cout << "=" << param.second;
58 /** The type of each element in the list.
60 The first string in the pair is the name of the parameter,
61 and the second string in the pair is its value (which may
65 std::pair<string_view, string_view>;
67 /// A constant iterator to the list
68 #if BOOST_BEAST_DOXYGEN
69 using const_iterator = __implementation_defined__;
74 /// Default constructor.
75 param_list() = default;
79 @param s A string containing the list contents. The string
80 must remain valid for the lifetime of the container.
83 param_list(string_view s)
88 /// Return a const iterator to the beginning of the list
89 const_iterator begin() const;
91 /// Return a const iterator to the end of the list
92 const_iterator end() const;
94 /// Return a const iterator to the beginning of the list
95 const_iterator cbegin() const;
97 /// Return a const iterator to the end of the list
98 const_iterator cend() const;
101 //------------------------------------------------------------------------------
103 /** A list of extensions in a comma separated HTTP field value.
105 This container allows iteration of the extensions in an HTTP
106 field value. The extension list is a comma separated list of
107 token parameter list pairs.
109 If a parsing error is encountered while iterating the string,
110 the behavior of the container will be as if a string containing
111 only characters up to but excluding the first invalid character
112 was used to construct the list.
116 ext-list = *( "," OWS ) ext *( OWS "," [ OWS ext ] )
117 ext = token param-list
118 param-list = *( OWS ";" OWS param )
119 param = token OWS [ "=" OWS ( token / quoted-string ) ]
122 To use this class, construct with the string to be parsed and
123 then use @ref begin and @ref end, or range-for to iterate each
128 for(auto const& ext : ext_list{"none, 7z;level=9, zip;no_context_takeover;bits=15"})
130 std::cout << ext.first << "\n";
131 for(auto const& param : ext.second)
133 std::cout << ";" << param.first;
134 if(! param.second.empty())
135 std::cout << "=" << param.second;
143 using iter_type = string_view::const_iterator;
148 /** The type of each element in the list.
150 The first element of the pair is the extension token, and the
151 second element of the pair is an iterable container holding the
152 extension's name/value parameters.
154 using value_type = std::pair<string_view, param_list>;
156 /// A constant iterator to the list
157 #if BOOST_BEAST_DOXYGEN
158 using const_iterator = __implementation_defined__;
160 class const_iterator;
163 /** Construct a list.
165 @param s A string containing the list contents. The string
166 must remain valid for the lifetime of the container.
169 ext_list(string_view s)
174 /// Return a const iterator to the beginning of the list
175 const_iterator begin() const;
177 /// Return a const iterator to the end of the list
178 const_iterator end() const;
180 /// Return a const iterator to the beginning of the list
181 const_iterator cbegin() const;
183 /// Return a const iterator to the end of the list
184 const_iterator cend() const;
186 /** Find a token in the list.
188 @param s The token to find. A case-insensitive comparison is used.
190 @return An iterator to the matching token, or `end()` if no
195 find(string_view const& s);
197 /** Return `true` if a token is present in the list.
199 @param s The token to find. A case-insensitive comparison is used.
203 exists(string_view const& s);
206 //------------------------------------------------------------------------------
208 /** A list of tokens in a comma separated HTTP field value.
210 This container allows iteration of a list of items in a
211 header field value. The input is a comma separated list of
214 If a parsing error is encountered while iterating the string,
215 the behavior of the container will be as if a string containing
216 only characters up to but excluding the first invalid character
217 was used to construct the list.
221 token-list = *( "," OWS ) token *( OWS "," [ OWS token ] )
224 To use this class, construct with the string to be parsed and
225 then use @ref begin and @ref end, or range-for to iterate each
230 for(auto const& token : token_list{"apple, pear, banana"})
231 std::cout << token << "\n";
236 using iter_type = string_view::const_iterator;
241 /// The type of each element in the token list.
242 using value_type = string_view;
244 /// A constant iterator to the list
245 #if BOOST_BEAST_DOXYGEN
246 using const_iterator = __implementation_defined__;
248 class const_iterator;
251 /** Construct a list.
253 @param s A string containing the list contents. The string
254 must remain valid for the lifetime of the container.
257 token_list(string_view s)
262 /// Return a const iterator to the beginning of the list
263 const_iterator begin() const;
265 /// Return a const iterator to the end of the list
266 const_iterator end() const;
268 /// Return a const iterator to the beginning of the list
269 const_iterator cbegin() const;
271 /// Return a const iterator to the end of the list
272 const_iterator cend() const;
274 /** Return `true` if a token is present in the list.
276 @param s The token to find. A case-insensitive comparison is used.
280 exists(string_view const& s);
283 /** A list of tokens in a comma separated HTTP field value.
285 This container allows iteration of a list of items in a
286 header field value. The input is a comma separated list of
289 If a parsing error is encountered while iterating the string,
290 the behavior of the container will be as if a string containing
291 only characters up to but excluding the first invalid character
292 was used to construct the list.
296 token-list = *( "," OWS ) token *( OWS "," [ OWS token ] )
299 To use this class, construct with the string to be parsed and
300 then use `begin` and `end`, or range-for to iterate each item:
304 for(auto const& token : token_list{"apple, pear, banana"})
305 std::cout << token << "\n";
308 using opt_token_list =
309 detail::basic_parsed_list<
310 detail::opt_token_list_policy>;
312 /** Returns `true` if a parsed list is parsed without errors.
314 This function iterates a single pass through a parsed list
315 and returns `true` if there were no parsing errors, else
318 template<class Policy>
320 validate_list(detail::basic_parsed_list<
321 Policy> const& list);
327 #include <boost/beast/http/impl/rfc7230.hpp>