Boost C++ Libraries

PrevUpHomeNext

Class cookies

boost::taar::cookies — Owning, unordered container of request cookies.

Synopsis

// 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);
};

Description

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 functions

  1. cookies() = default;
    Construct an empty container.
  2. 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).
  3. cookies(std::initializer_list< value_type > init);
  4. size_type size() const noexcept;
  5. auto begin() noexcept;
  6. auto begin() const noexcept;
  7. auto cbegin() const noexcept;
  8. auto end() noexcept;
  9. auto end() const noexcept;
  10. auto cend() const noexcept;
  11. mapped_type const & at(key_type const & name) const;
  12. mapped_type & at(key_type const & name);
  13. mapped_type const & operator[](key_type const & name) const;
  14. mapped_type & operator[](key_type const & name);
  15. void clear() noexcept;
  16. bool empty() const noexcept;
  17. size_type count(key_type const & key) const;
  18. iterator find(key_type const & key);
  19. const_iterator find(key_type const & key) const;
  20. bool contains(key_type const & key) const;
  21. std::pair< iterator, iterator > equal_range(key_type const & key);
  22. std::pair< const_iterator, const_iterator > 
    equal_range(key_type const & key) const;

cookies friend functions

  1. error 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.

  2. 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.


PrevUpHomeNext