![]() |
boost::taar::cookies — Owning, unordered container of request cookies.
// In header: <boost/taar/core/cookies.hpp> class cookies { public: // types typedef std::unordered_map< std::string, std::string > items_type; typedef items_type::key_type key_type; typedef items_type::mapped_type mapped_type; typedef items_type::value_type value_type; typedef items_type::size_type size_type; typedef items_type::difference_type difference_type; typedef items_type::hasher hasher; typedef items_type::key_equal key_equal; typedef items_type::allocator_type allocator_type; typedef items_type::reference reference; typedef items_type::const_reference const_reference; typedef items_type::pointer pointer; typedef items_type::const_pointer const_pointer; typedef items_type::iterator iterator; typedef items_type::const_iterator const_iterator; typedef items_type::local_iterator local_iterator; typedef items_type::const_local_iterator const_local_iterator; typedef items_type::node_type node_type; typedef items_type::insert_return_type insert_return_type; // public member functions cookies() = default; cookies(std::string_view); cookies(std::initializer_list< value_type >); size_type size() const noexcept; auto begin() noexcept; auto begin() const noexcept; auto cbegin() const noexcept; auto end() noexcept; auto end() const noexcept; auto cend() const noexcept; mapped_type const & at(key_type const &) const; mapped_type & at(key_type const &); mapped_type const & operator[](key_type const &) const; mapped_type & operator[](key_type const &); void clear() noexcept; bool empty() const noexcept; size_type count(key_type const &) const; iterator find(key_type const &); const_iterator find(key_type const &) const; bool contains(key_type const &) const; std::pair< iterator, iterator > equal_range(key_type const &); std::pair< const_iterator, const_iterator > equal_range(key_type const &) const; // friend functions error parse_cookies(std::string_view, cookies &); taar::result< cookies > parse_cookies(std::string_view); };
A cookies instance stores the percent-decoded name/value pairs that were parsed from a request's Cookie header. The session populates one of these per request when any registered matcher or handler needs cookie data; user code typically does not construct it directly.
The interface mirrors std::unordered_map<std::string, std::string> enough that the usual find, contains, at, range-based for, and structured-binding patterns all work.
To parse a cookie string outside a session, use the free function parse_cookies.
cookies public member functionscookies() = default;Construct an empty container.
cookies(std::string_view cookie_string);Construct by parsing a
Cookie header value.
Throws: |
boost::taar::exception if the header is malformed (carries an error::invalid_cookie_format code). |
cookies(std::initializer_list< value_type > init);
size_type size() const noexcept;
auto begin() noexcept;
auto begin() const noexcept;
auto cbegin() const noexcept;
auto end() noexcept;
auto end() const noexcept;
auto cend() const noexcept;
mapped_type const & at(key_type const & name) const;
mapped_type & at(key_type const & name);
mapped_type const & operator[](key_type const & name) const;
mapped_type & operator[](key_type const & name);
void clear() noexcept;
bool empty() const noexcept;
size_type count(key_type const & key) const;
iterator find(key_type const & key);
const_iterator find(key_type const & key) const;
bool contains(key_type const & key) const;
std::pair< iterator, iterator > equal_range(key_type const & key);
std::pair< const_iterator, const_iterator > equal_range(key_type const & key) const;
cookies friend functionserror parse_cookies(std::string_view cookie_string, cookies & result);Parse cookie_string and append the results into result.
Returns: |
error::success on success or error::invalid_cookie_format on a syntax error. |
taar::result< cookies > parse_cookies(std::string_view cookie_string);Parse cookie_string into a fresh cookies.
Returns: |
A boost::taar::result carrying the parsed cookies, or a failure with an error code if the input is malformed. |