#include <icy/http/cookie.h>HTTP cookie value plus its response/header attributes.
A cookie is a small amount of information sent by a Web server to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management.
A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
This class supports both the Version 0 (by Netscape) and Version 1 (by RFC 2109) cookie specifications. By default, cookies are created using Version 0 to ensure the best interoperability.
| Return | Name | Description |
|---|---|---|
Cookie | Creates an empty Cookie. | |
Cookie explicit | Creates a cookie with the given name. The cookie never expires. | |
Cookie explicit | Creates a cookie from the given NVCollection. | |
Cookie | Creates a cookie with the given name and value. The cookie never expires. | |
Cookie | Creates the Cookie by copying another one. | |
~Cookie | Destroys the Cookie. | |
Cookie & | operator= | Assigns a cookie. |
void | setVersion | Sets the version of the cookie. |
int | getVersion const inline | Returns the version of the cookie, which is either 0 or 1. |
void | setName | Sets the name of the cookie. |
const std::string & | getName const inline | Returns the name of the cookie. |
void | setValue | Sets the value of the cookie. |
const std::string & | getValue const inline | Returns the value of the cookie. |
void | setComment | Sets the comment for the cookie. |
const std::string & | getComment const inline | Returns the comment for the cookie. |
void | setDomain | Sets the domain for the cookie. |
const std::string & | getDomain const inline | Returns the domain for the cookie. |
void | setPath | Sets the path for the cookie. |
const std::string & | getPath const inline | Returns the path for the cookie. |
void | setSecure | Sets the value of the secure flag for the cookie. |
bool | getSecure const inline | Returns the value of the secure flag for the cookie. |
void | setMaxAge | Sets the maximum age in seconds for the cookie. |
int | getMaxAge const inline | Returns the maximum age in seconds for the cookie. |
void | setHttpOnly | Sets the HttpOnly flag for the cookie. |
bool | getHttpOnly const inline | Returns true if the cookie's HttpOnly flag is set. |
std::string | toString const | Returns a std::string representation of the cookie, suitable for use in a Set-Cookie header. |
Cookie()Creates an empty Cookie.
explicit
explicit Cookie(const std::string & name)Creates a cookie with the given name. The cookie never expires.
explicit
explicit Cookie(const NVCollection & nvc)Creates a cookie from the given NVCollection.
Cookie(const std::string & name, const std::string & value)Creates a cookie with the given name and value. The cookie never expires.
Note: If value contains whitespace or non-alphanumeric characters, the value should be escaped by calling escape() before passing it to the constructor.
Cookie(const Cookie & cookie)Creates the Cookie by copying another one.
~Cookie()Destroys the Cookie.
Cookie & operator=(const Cookie & cookie)Assigns a cookie.
void setVersion(int version)Sets the version of the cookie.
Version must be either 0 (denoting a Netscape cookie) or 1 (denoting a RFC 2109 cookie).
const inline
inline int getVersion() constReturns the version of the cookie, which is either 0 or 1.
void setName(const std::string & name)Sets the name of the cookie.
const inline
inline const std::string & getName() constReturns the name of the cookie.
void setValue(const std::string & value)Sets the value of the cookie.
According to the cookie specification, the size of the value should not exceed 4 Kbytes.
Note: If value contains whitespace or non-alphanumeric characters, the value should be escaped by calling escape() prior to passing it to setName().
const inline
inline const std::string & getValue() constReturns the value of the cookie.
void setComment(const std::string & comment)Sets the comment for the cookie.
Comments are only supported for version 1 cookies.
const inline
inline const std::string & getComment() constReturns the comment for the cookie.
void setDomain(const std::string & domain)Sets the domain for the cookie.
const inline
inline const std::string & getDomain() constReturns the domain for the cookie.
void setPath(const std::string & path)Sets the path for the cookie.
const inline
inline const std::string & getPath() constReturns the path for the cookie.
void setSecure(bool secure)Sets the value of the secure flag for the cookie.
const inline
inline bool getSecure() constReturns the value of the secure flag for the cookie.
void setMaxAge(int maxAge)Sets the maximum age in seconds for the cookie.
A value of -1 causes the cookie to never expire on the client.
A value of 0 deletes the cookie on the client.
const inline
inline int getMaxAge() constReturns the maximum age in seconds for the cookie.
void setHttpOnly(bool flag)Sets the HttpOnly flag for the cookie.
const inline
inline bool getHttpOnly() constReturns true if the cookie's HttpOnly flag is set.
const
std::string toString() constReturns a std::string representation of the cookie, suitable for use in a Set-Cookie header.
| Return | Name | Description |
|---|---|---|
std::string | escape static | Escapes the given std::string by replacing all non-alphanumeric characters with escape sequences in the form xx, where xx is the hexadecimal character code. |
std::string | unescape static | Unescapes the given std::string by replacing all escape sequences in the form xx with the respective characters. |
static
static std::string escape(std::string_view str)Escapes the given std::string by replacing all non-alphanumeric characters with escape sequences in the form xx, where xx is the hexadecimal character code.
static
static std::string unescape(std::string_view str)Unescapes the given std::string by replacing all escape sequences in the form xx with the respective characters.
| Return | Name | Description |
|---|---|---|
int | _version | |
std::string | _name | |
std::string | _value | |
std::string | _comment | |
std::string | _domain | |
std::string | _path | |
bool | _secure | |
int | _maxAge | |
bool | _httpOnly |
int _versionstd::string _namestd::string _valuestd::string _commentstd::string _domainstd::string _pathbool _secureint _maxAgebool _httpOnly