123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- //
- // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
- //
- // Distributed under the Boost Software License, Version 1.0. (See accompanying
- // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- //
- // Official repository: https://github.com/boostorg/beast
- //
- #ifndef BOOST_BEAST_HTTP_RFC7230_HPP
- #define BOOST_BEAST_HTTP_RFC7230_HPP
- #include <boost/beast/core/detail/config.hpp>
- #include <boost/beast/http/detail/rfc7230.hpp>
- #include <boost/beast/http/detail/basic_parsed_list.hpp>
- namespace boost {
- namespace beast {
- namespace http {
- /** A list of parameters in an HTTP extension field value.
- This container allows iteration of the parameter list in an HTTP
- extension. The parameter list is a series of name/value pairs
- with each pair starting with a semicolon. The value is optional.
- If a parsing error is encountered while iterating the string,
- the behavior of the container will be as if a string containing
- only characters up to but excluding the first invalid character
- was used to construct the list.
- @par BNF
- @code
- param-list = *( OWS ";" OWS param )
- param = token OWS [ "=" OWS ( token / quoted-string ) ]
- @endcode
- To use this class, construct with the string to be parsed and
- then use @ref begin and @ref end, or range-for to iterate each
- item:
- @par Example
- @code
- for(auto const& param : param_list{";level=9;no_context_takeover;bits=15"})
- {
- std::cout << ";" << param.first;
- if(! param.second.empty())
- std::cout << "=" << param.second;
- std::cout << "\n";
- }
- @endcode
- */
- class param_list
- {
- string_view s_;
- public:
- /** The type of each element in the list.
- The first string in the pair is the name of the parameter,
- and the second string in the pair is its value (which may
- be empty).
- */
- using value_type =
- std::pair<string_view, string_view>;
- /// A constant iterator to the list
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- class const_iterator;
- #endif
- /// Default constructor.
- param_list() = default;
- /** Construct a list.
- @param s A string containing the list contents. The string
- must remain valid for the lifetime of the container.
- */
- explicit
- param_list(string_view s)
- : s_(s)
- {
- }
- /// Return a const iterator to the beginning of the list
- const_iterator begin() const;
- /// Return a const iterator to the end of the list
- const_iterator end() const;
- /// Return a const iterator to the beginning of the list
- const_iterator cbegin() const;
- /// Return a const iterator to the end of the list
- const_iterator cend() const;
- };
- //------------------------------------------------------------------------------
- /** A list of extensions in a comma separated HTTP field value.
- This container allows iteration of the extensions in an HTTP
- field value. The extension list is a comma separated list of
- token parameter list pairs.
- If a parsing error is encountered while iterating the string,
- the behavior of the container will be as if a string containing
- only characters up to but excluding the first invalid character
- was used to construct the list.
- @par BNF
- @code
- ext-list = *( "," OWS ) ext *( OWS "," [ OWS ext ] )
- ext = token param-list
- param-list = *( OWS ";" OWS param )
- param = token OWS [ "=" OWS ( token / quoted-string ) ]
- @endcode
- To use this class, construct with the string to be parsed and
- then use @ref begin and @ref end, or range-for to iterate each
- item:
- @par Example
- @code
- for(auto const& ext : ext_list{"none, 7z;level=9, zip;no_context_takeover;bits=15"})
- {
- std::cout << ext.first << "\n";
- for(auto const& param : ext.second)
- {
- std::cout << ";" << param.first;
- if(! param.second.empty())
- std::cout << "=" << param.second;
- std::cout << "\n";
- }
- }
- @endcode
- */
- class ext_list
- {
- using iter_type = string_view::const_iterator;
- string_view s_;
- public:
- /** The type of each element in the list.
- The first element of the pair is the extension token, and the
- second element of the pair is an iterable container holding the
- extension's name/value parameters.
- */
- using value_type = std::pair<string_view, param_list>;
- /// A constant iterator to the list
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- class const_iterator;
- #endif
- /** Construct a list.
- @param s A string containing the list contents. The string
- must remain valid for the lifetime of the container.
- */
- explicit
- ext_list(string_view s)
- : s_(s)
- {
- }
- /// Return a const iterator to the beginning of the list
- const_iterator begin() const;
- /// Return a const iterator to the end of the list
- const_iterator end() const;
- /// Return a const iterator to the beginning of the list
- const_iterator cbegin() const;
- /// Return a const iterator to the end of the list
- const_iterator cend() const;
- /** Find a token in the list.
- @param s The token to find. A case-insensitive comparison is used.
- @return An iterator to the matching token, or `end()` if no
- token exists.
- */
- BOOST_BEAST_DECL
- const_iterator
- find(string_view const& s);
- /** Return `true` if a token is present in the list.
- @param s The token to find. A case-insensitive comparison is used.
- */
- BOOST_BEAST_DECL
- bool
- exists(string_view const& s);
- };
- //------------------------------------------------------------------------------
- /** A list of tokens in a comma separated HTTP field value.
- This container allows iteration of a list of items in a
- header field value. The input is a comma separated list of
- tokens.
- If a parsing error is encountered while iterating the string,
- the behavior of the container will be as if a string containing
- only characters up to but excluding the first invalid character
- was used to construct the list.
- @par BNF
- @code
- token-list = *( "," OWS ) token *( OWS "," [ OWS token ] )
- @endcode
- To use this class, construct with the string to be parsed and
- then use @ref begin and @ref end, or range-for to iterate each
- item:
- @par Example
- @code
- for(auto const& token : token_list{"apple, pear, banana"})
- std::cout << token << "\n";
- @endcode
- */
- class token_list
- {
- using iter_type = string_view::const_iterator;
- string_view s_;
- public:
- /// The type of each element in the token list.
- using value_type = string_view;
- /// A constant iterator to the list
- #if BOOST_BEAST_DOXYGEN
- using const_iterator = __implementation_defined__;
- #else
- class const_iterator;
- #endif
- /** Construct a list.
- @param s A string containing the list contents. The string
- must remain valid for the lifetime of the container.
- */
- explicit
- token_list(string_view s)
- : s_(s)
- {
- }
- /// Return a const iterator to the beginning of the list
- const_iterator begin() const;
- /// Return a const iterator to the end of the list
- const_iterator end() const;
- /// Return a const iterator to the beginning of the list
- const_iterator cbegin() const;
- /// Return a const iterator to the end of the list
- const_iterator cend() const;
- /** Return `true` if a token is present in the list.
- @param s The token to find. A case-insensitive comparison is used.
- */
- BOOST_BEAST_DECL
- bool
- exists(string_view const& s);
- };
- /** A list of tokens in a comma separated HTTP field value.
- This container allows iteration of a list of items in a
- header field value. The input is a comma separated list of
- tokens.
- If a parsing error is encountered while iterating the string,
- the behavior of the container will be as if a string containing
- only characters up to but excluding the first invalid character
- was used to construct the list.
- @par BNF
- @code
- token-list = *( "," OWS ) token *( OWS "," [ OWS token ] )
- @endcode
- To use this class, construct with the string to be parsed and
- then use `begin` and `end`, or range-for to iterate each item:
- @par Example
- @code
- for(auto const& token : token_list{"apple, pear, banana"})
- std::cout << token << "\n";
- @endcode
- */
- using opt_token_list =
- detail::basic_parsed_list<
- detail::opt_token_list_policy>;
- /** Returns `true` if a parsed list is parsed without errors.
- This function iterates a single pass through a parsed list
- and returns `true` if there were no parsing errors, else
- returns `false`.
- */
- template<class Policy>
- bool
- validate_list(detail::basic_parsed_list<
- Policy> const& list);
- } // http
- } // beast
- } // boost
- #include <boost/beast/http/impl/rfc7230.hpp>
- #endif
|