Wt
4.11.1
|
#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. More... | |
Cookie (const std::string &name, const std::string &value, const Wt::WDateTime &expires) | |
Constructor for a cookie that expires at a certain datetime. More... | |
Cookie (const std::string &name, const std::string &value, const std::chrono::seconds &maxAge) | |
Constructor for a cookie that expires after certain duration. More... | |
const std::string & | name () const |
The cookie name. | |
void | setValue (const std::string &value) |
Sets the cookie value. More... | |
const std::string & | value () const |
The cookie value. More... | |
void | setExpires (const Wt::WDateTime &expires) |
Sets when the cookie will expire. More... | |
const Wt::WDateTime & | expires () const |
The cookie expiration. More... | |
void | setMaxAge (const std::chrono::seconds &maxAge) |
Sets the cookie's Max-Age. More... | |
const std::chrono::seconds & | maxAge () const |
The cookie's Max-Age. More... | |
void | setDomain (const std::string &domain) |
Sets the cookie domain. More... | |
const std::string & | domain () const |
The cookie domain. More... | |
void | setPath (const std::string &path) |
Sets the cookie path. More... | |
const std::string & | path () const |
The cookie path. More... | |
void | setSecure (bool secure) |
Sets if the cookie must be sent over a secure connection. More... | |
bool | secure () const |
Returns if the cookie must be sent over secure connection. More... | |
void | setHttpOnly (bool httpOnly) |
Sets if the cookie is only accessible through HTTP. More... | |
bool | httpOnly () const |
Returns if the cookie is only accessible through HTTP. More... | |
void | setSameSite (SameSite sameSite) |
Sets the cookie SameSite attribute. More... | |
SameSite | sameSite () const |
The cookie SameSite attribute. More... | |
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.
const std::string& Wt::Http::Cookie::path | ( | ) | const |
The cookie path.
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.
void Wt::Http::Cookie::setDomain | ( | const std::string & | domain | ) |
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).
void Wt::Http::Cookie::setHttpOnly | ( | bool | httpOnly | ) |
void Wt::Http::Cookie::setMaxAge | ( | const std::chrono::seconds & | maxAge | ) |
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.
void Wt::Http::Cookie::setPath | ( | const std::string & | path | ) |
Sets the cookie path.
By default the cookie only applies to the application deployment path (WEnvironment::deploymentPath()).
void Wt::Http::Cookie::setSameSite | ( | SameSite | sameSite | ) |
Sets the cookie SameSite attribute.
The default value is SameSite::Lax.
void Wt::Http::Cookie::setSecure | ( | bool | secure | ) |
Sets if the cookie must be sent over a secure connection.
The default value is false.
void Wt::Http::Cookie::setValue | ( | const std::string & | value | ) |
Sets the cookie value.
const std::string& Wt::Http::Cookie::value | ( | ) | const |
The cookie value.