16#include <drogon/exports.h>
17#include <trantor/utils/Date.h>
18#include <trantor/utils/Logger.h>
92 domain_ = std::move(
domain);
108 path_ = std::move(
path);
124 key_ = std::move(
key);
140 value_ = std::move(
value);
164 partitioned_ = partitioned;
219 const std::string &
path()
const
235 const std::string &
key()
const
270 operator bool()
const
272 return (!key_.empty()) && (!value_.empty());
353 static bool stricmp(
const std::string_view str1,
354 const std::string_view str2)
356 auto str1Len{str1.length()};
357 auto str2Len{str2.length()};
358 if (str1Len != str2Len)
360 for (
size_t idx{0}; idx < str1Len; ++idx)
362 auto lowerChar{tolower(str1[idx])};
364 if (lowerChar != str2[idx])
379 return Cookie::SameSite::kLax;
381 return Cookie::SameSite::kStrict;
383 return Cookie::SameSite::kNone;
388 <<
"' is not a valid SameSite policy. 'Null', 'Lax', 'Strict' "
390 "'None' are proper values. Return value is SameSite::kNull.";
392 return Cookie::SameSite::kNull;
405 case SameSite::kStrict:
407 case SameSite::kNone:
409 case SameSite::kNull:
417 trantor::Date expiresDate_{(std::numeric_limits<int64_t>::max)()};
418 bool httpOnly_{
true};
420 bool partitioned_{
false};
425 std::optional<int> maxAge_;
426 SameSite sameSite_{SameSite::kNull};
this class represents a cookie entity.
Definition Cookie.h:32
const std::string & getPath() const
Get the path of the cookie.
Definition Cookie.h:227
void setDomain(std::string &&domain)
Set the domain of the cookie.
Definition Cookie.h:90
static SameSite convertString2SameSite(std::string_view sameSite)
Converts a string value to its associated enum class SameSite value.
Definition Cookie.h:376
const std::string & getValue() const
Get the value of the cookie.
Definition Cookie.h:259
static bool stricmp(const std::string_view str1, const std::string_view str2)
Compare two strings ignoring the their cases.
Definition Cookie.h:353
void setHttpOnly(bool only)
Set if the cookie is HTTP only.
Definition Cookie.h:66
SameSite sameSite() const
Get the same site of the cookie.
Definition Cookie.h:327
const std::string & domain() const
Get the domain of the cookie.
Definition Cookie.h:203
void setPath(const std::string &path)
Set the path of the cookie.
Definition Cookie.h:98
void setPartitioned(bool partitioned)
Set the partitioned status of the cookie.
Definition Cookie.h:162
std::optional< int > getMaxAge() const
Get the max-age of the cookie.
Definition Cookie.h:319
bool isPartitioned() const
Check if the cookie is partitioned.
Definition Cookie.h:303
const std::string & path() const
Get the path of the cookie.
Definition Cookie.h:219
void setSecure(bool secure)
Set if the cookie is secure.
Definition Cookie.h:74
SameSite getSameSite() const
Get the same site of the cookie.
Definition Cookie.h:335
const std::string & getKey() const
Get the keyword of the cookie.
Definition Cookie.h:243
void setKey(const std::string &key)
Set the key of the cookie.
Definition Cookie.h:114
bool isSecure() const
Check if the cookie is secure.
Definition Cookie.h:292
void setKey(std::string &&key)
Set the key of the cookie.
Definition Cookie.h:122
std::string getCookieString() const
Get the string value of the cookie.
Definition Cookie.h:179
std::optional< int > maxAge() const
Get the max-age of the cookie.
Definition Cookie.h:311
static std::string_view convertSameSite2String(SameSite sameSite)
Converts an enum class SameSite value to its associated string value.
Definition Cookie.h:399
bool isHttpOnly() const
Check if the cookie is HTTP only.
Definition Cookie.h:281
void setSameSite(SameSite sameSite)
Set the same site of the cookie.
Definition Cookie.h:154
void setExpiresDate(const trantor::Date &date)
Set the Expires Date.
Definition Cookie.h:58
const std::string & key() const
Get the keyword of the cookie.
Definition Cookie.h:235
const std::string & value() const
Get the value of the cookie.
Definition Cookie.h:251
const trantor::Date & expiresDate() const
Get the expiration date of the cookie.
Definition Cookie.h:187
void setPath(std::string &&path)
Set the path of the cookie.
Definition Cookie.h:106
const trantor::Date & getExpiresDate() const
Get the expiration date of the cookie.
Definition Cookie.h:195
void setValue(std::string &&value)
Set the value of the cookie.
Definition Cookie.h:138
std::string cookieString() const
Get the string value of the cookie.
Cookie(std::string key, std::string value)
Constructor.
Definition Cookie.h:39
void setValue(const std::string &value)
Set the value of the cookie.
Definition Cookie.h:130
void setMaxAge(int value)
Set the max-age of the cookie.
Definition Cookie.h:146
const std::string & getDomain() const
Get the domain of the cookie.
Definition Cookie.h:211
void setDomain(const std::string &domain)
Set the domain of the cookie.
Definition Cookie.h:82
Drogon Test is a minimal effort test framework developed because the major C++ test frameworks doesn'...
Definition Attribute.h:23