drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::Cookie Class Reference

this class represents a cookie entity. More...

#include <drogon/Cookie.h>

Public Types

enum class  SameSite { kNull , kLax , kStrict , kNone }

Public Member Functions

 Cookie (std::string key, std::string value)
 Constructor.
void setExpiresDate (const trantor::Date &date)
 Set the Expires Date.
void setHttpOnly (bool only)
 Set if the cookie is HTTP only.
void setSecure (bool secure)
 Set if the cookie is secure.
void setDomain (const std::string &domain)
 Set the domain of the cookie.
void setDomain (std::string &&domain)
 Set the domain of the cookie.
void setPath (const std::string &path)
 Set the path of the cookie.
void setPath (std::string &&path)
 Set the path of the cookie.
void setKey (const std::string &key)
 Set the key of the cookie.
void setKey (std::string &&key)
 Set the key of the cookie.
void setValue (const std::string &value)
 Set the value of the cookie.
void setValue (std::string &&value)
 Set the value of the cookie.
void setMaxAge (int value)
 Set the max-age of the cookie.
void setSameSite (SameSite sameSite)
 Set the same site of the cookie.
void setPartitioned (bool partitioned)
 Set the partitioned status of the cookie.
std::string cookieString () const
 Get the string value of the cookie.
std::string getCookieString () const
 Get the string value of the cookie.
const trantor::Date & expiresDate () const
 Get the expiration date of the cookie.
const trantor::Date & getExpiresDate () const
 Get the expiration date of the cookie.
const std::string & domain () const
 Get the domain of the cookie.
const std::string & getDomain () const
 Get the domain of the cookie.
const std::string & path () const
 Get the path of the cookie.
const std::string & getPath () const
 Get the path of the cookie.
const std::string & key () const
 Get the keyword of the cookie.
const std::string & getKey () const
 Get the keyword of the cookie.
const std::string & value () const
 Get the value of the cookie.
const std::string & getValue () const
 Get the value of the cookie.
 operator bool () const
 Check if the cookie is empty.
bool isHttpOnly () const
 Check if the cookie is HTTP only.
bool isSecure () const
 Check if the cookie is secure.
bool isPartitioned () const
 Check if the cookie is partitioned.
std::optional< int > maxAge () const
 Get the max-age of the cookie.
std::optional< int > getMaxAge () const
 Get the max-age of the cookie.
SameSite sameSite () const
 Get the same site of the cookie.
SameSite getSameSite () const
 Get the same site of the cookie.

Static Public Member Functions

static bool stricmp (const std::string_view str1, const std::string_view str2)
 Compare two strings ignoring the their cases.
static SameSite convertString2SameSite (std::string_view sameSite)
 Converts a string value to its associated enum class SameSite value.
static std::string_view convertSameSite2String (SameSite sameSite)
 Converts an enum class SameSite value to its associated string value.

Detailed Description

this class represents a cookie entity.

Constructor & Destructor Documentation

◆ Cookie()

drogon::Cookie::Cookie ( std::string key,
std::string value )
inline

Constructor.

Parameters
keykey of the cookie
valuevalue of the cookie

Member Function Documentation

◆ isHttpOnly()

bool drogon::Cookie::isHttpOnly ( ) const
inline

Check if the cookie is HTTP only.

Returns
true means the cookie is HTTP only
false means the cookie is not HTTP only

◆ isPartitioned()

bool drogon::Cookie::isPartitioned ( ) const
inline

Check if the cookie is partitioned.

Returns
true means the cookie is partitioned.
false means the cookie is not partitioned.

◆ isSecure()

bool drogon::Cookie::isSecure ( ) const
inline

Check if the cookie is secure.

Returns
true means the cookie is secure.
false means the cookie is not secure.

◆ operator bool()

drogon::Cookie::operator bool ( ) const
inline

Check if the cookie is empty.

Returns
true means the cookie is not empty
false means the cookie is empty

◆ setExpiresDate()

void drogon::Cookie::setExpiresDate ( const trantor::Date & date)
inline

Set the Expires Date.

Parameters
dateThe expiration date

◆ stricmp()

bool drogon::Cookie::stricmp ( const std::string_view str1,
const std::string_view str2 )
inlinestatic

Compare two strings ignoring the their cases.

Parameters
str1string to check its value
str2string to check against, written in lower case
Note
the function is optimized to check for cookie's samesite value where we check if the value equals to a specific value we already know in str2. so the function doesn't apply tolower to the second argument str2 as it's always in lower case.
Returns
true if both strings are equal ignoring case

The documentation for this class was generated from the following file: