Boost C++ Libraries

PrevUpHomeNext

Struct template cookie_t

boost::taar::matcher::cookie_t — A placeholder that produces matchers over individual request cookies.

Synopsis

// In header: <boost/taar/matcher/cookie.hpp>

template<typename FieldsType = boost::beast::http::fields> 
struct cookie_t {
  // types
  typedef boost::beast::http::request_header< FieldsType > request_type;  // The request type these matchers accept. 

  // member classes/structs/unions

  // A handle to a particular cookie by name.

  struct cookie_item {

    // friend functions
    auto exist(cookie_item);

    // public data members
    std::string name;    // The cookie name this item refers to. 
  };

  // public member functions
  auto operator()(std::string) const;
};

Description

cookie_t is not used directly; call its function-call operator with a cookie name to obtain a cookie_item, then compose that with the equality operators or with the free function exist().

The session is responsible for parsing the Cookie header into a boost::taar::cookies map and passing it to the matcher. As a result cookie matchers can only be used inside a session that has cookie parsing enabled.

using boost::taar::matcher::cookie;

auto logged_in = exist(cookie("session"));
auto admin     = cookie("role") == "admin";

The produced operand carries cookie_eq_constraint, cookie_ne_constraint, or cookie_exists_constraint metadata with the cookie name and the constrained value in its captures tuple. Existence matchers leave the captured value empty.

Template Parameters

  1. typename FieldsType = boost::beast::http::fields

    The Beast HTTP fields container of the request to inspect. Defaults to boost::beast::http::fields.

cookie_t public member functions

  1. auto operator()(std::string name) const;
    Build a cookie_item for the cookie named name.

PrevUpHomeNext