Wt
4.10.4
|
#include <Wt/Http/Cookie.h>
Public Types | |
enum class | SameSite { None , Lax , Strict } |
Enumeration of SameSite attribute values. More... | |
Public Member Functions | |
Cookie (const std::string &name) | |
Constructor for cookie without value. | |
Cookie (const std::string &name, const std::string &value, const Wt::WDateTime &expires) | |
Constructor for a cookie that expires at a certain datetime. | |
Cookie (const std::string &name, const std::string &value, const std::chrono::seconds &maxAge) | |
Constructor for a cookie that expires after certain duration. | |
const std::string & | name () const |
The cookie name. | |
void | setValue (const std::string &value) |
Sets the cookie value. | |
const std::string & | value () const |
The cookie value. | |
void | setExpires (const Wt::WDateTime &expires) |
Sets when the cookie will expire. | |
const Wt::WDateTime & | expires () const |
The cookie expiration. | |
void | setMaxAge (const std::chrono::seconds &maxAge) |
Sets the cookie's Max-Age. | |
const std::chrono::seconds & | maxAge () const |
The cookie's Max-Age. | |
void | setDomain (const std::string &domain) |
Sets the cookie domain. | |
const std::string & | domain () const |
The cookie domain. | |
void | setPath (const std::string &path) |
Sets the cookie path. | |
const std::string & | path () const |
The cookie path. | |
void | setSecure (bool secure) |
Sets if the cookie must be sent over a secure connection. | |
bool | secure () const |
Returns if the cookie must be sent over secure connection. | |
void | setHttpOnly (bool httpOnly) |
Sets if the cookie is only accessible through HTTP. | |
bool | httpOnly () const |
Returns if the cookie is only accessible through HTTP. | |
void | setSameSite (SameSite sameSite) |
Sets the cookie SameSite attribute. | |
SameSite | sameSite () const |
The cookie SameSite attribute. | |
An HTTP Cookie.
Cookies can be set with WApplication::setCookie(const Http::Cookie&) and removed with WApplication::removeCookie(const Http::Cookie&).
|
strong |
|
explicit |
Constructor for cookie without value.
Allows you to only specify the name of the cookie. This can be useful if the intention is to pass it to WApplication::removeCookie(), in which case no value is needed.
Wt::Http::Cookie::Cookie | ( | const std::string & | name, |
const std::string & | value, | ||
const Wt::WDateTime & | expires ) |
Constructor for a cookie that expires at a certain datetime.
The name must be a valid cookie name (of type 'token': no special characters or separators, see RFC2616 page 16). The value may be anything.
Wt::Http::Cookie::Cookie | ( | const std::string & | name, |
const std::string & | value, | ||
const std::chrono::seconds & | maxAge ) |
Constructor for a cookie that expires after certain duration.
The name must be a valid cookie name (of type 'token': no special characters or separators, see RFC2616 page 16). The value may be anything.
const std::string & Wt::Http::Cookie::domain | ( | ) | const |
The cookie domain.
const Wt::WDateTime & Wt::Http::Cookie::expires | ( | ) | const |
The cookie expiration.
bool Wt::Http::Cookie::httpOnly | ( | ) | const |
Returns if the cookie is only accessible through HTTP.
const std::chrono::seconds & Wt::Http::Cookie::maxAge | ( | ) | const |
The cookie's Max-Age.
SameSite Wt::Http::Cookie::sameSite | ( | ) | const |
The cookie SameSite attribute.
bool Wt::Http::Cookie::secure | ( | ) | const |
Returns if the cookie must be sent over secure connection.
Sets the cookie domain.
By default the Domain attribute is omitted, which the browser interprets as the current domain (not including subdomains).
void Wt::Http::Cookie::setExpires | ( | const Wt::WDateTime & | expires | ) |
Sets when the cookie will expire.
If WDateTime::isNull(), it will be a session cookie (which expires when the browser is closed).
Sets the cookie's Max-Age.
The number of seconds until the cookie expires. Note that if both Expires and Max-Age are set, maxAge has precedence. When the duration is negative, Max-Age will not be set.
Sets the cookie path.
By default the cookie only applies to the application deployment path (WEnvironment::deploymentPath()).
Sets the cookie SameSite attribute.
The default value is SameSite::Lax.
Sets if the cookie must be sent over a secure connection.
The default value is false.
const std::string & Wt::Http::Cookie::value | ( | ) | const |
The cookie value.