Cookie
Cookie
#include <icy/http/cookie.h>class CookieDefined in src/http/include/icy/http/cookie.h:39
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.
List of all members
| Name | Kind | Owner |
|---|---|---|
Cookie | function | Declared here |
Cookie | function | Declared here |
Cookie | function | Declared here |
Cookie | function | Declared here |
Cookie | function | Declared here |
~Cookie | function | Declared here |
operator= | function | Declared here |
setVersion | function | Declared here |
getVersion | function | Declared here |
setName | function | Declared here |
getName | function | Declared here |
setValue | function | Declared here |
getValue | function | Declared here |
setComment | function | Declared here |
getComment | function | Declared here |
setDomain | function | Declared here |
getDomain | function | Declared here |
setPath | function | Declared here |
getPath | function | Declared here |
setSecure | function | Declared here |
getSecure | function | Declared here |
setMaxAge | function | Declared here |
getMaxAge | function | Declared here |
setHttpOnly | function | Declared here |
getHttpOnly | function | Declared here |
toString | function | Declared here |
escape | function | Declared here |
unescape | function | Declared here |
_version | variable | Declared here |
_name | variable | Declared here |
_value | variable | Declared here |
_comment | variable | Declared here |
_domain | variable | Declared here |
_path | variable | Declared here |
_secure | variable | Declared here |
_maxAge | variable | Declared here |
_httpOnly | variable | Declared here |
Public Methods
| 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
Cookie()Defined in src/http/include/icy/http/cookie.h:43
Creates an empty Cookie.
Cookie
explicit
explicit Cookie(const std::string & name)Defined in src/http/include/icy/http/cookie.h:47
Creates a cookie with the given name. The cookie never expires.
Cookie
explicit
explicit Cookie(const NVCollection & nvc)Defined in src/http/include/icy/http/cookie.h:50
Creates a cookie from the given NVCollection.
Cookie
Cookie(const std::string & name, const std::string & value)Defined in src/http/include/icy/http/cookie.h:58
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
Cookie(const Cookie & cookie)Defined in src/http/include/icy/http/cookie.h:61
Creates the Cookie by copying another one.
~Cookie
~Cookie()Defined in src/http/include/icy/http/cookie.h:64
Destroys the Cookie.
operator=
Cookie & operator=(const Cookie & cookie)Defined in src/http/include/icy/http/cookie.h:67
Assigns a cookie.
setVersion
void setVersion(int version)Defined in src/http/include/icy/http/cookie.h:73
Sets the version of the cookie.
Version must be either 0 (denoting a Netscape cookie) or 1 (denoting a RFC 2109 cookie).
getVersion
const inline
inline int getVersion() constDefined in src/http/include/icy/http/cookie.h:77
Returns the version of the cookie, which is either 0 or 1.
setName
void setName(const std::string & name)Defined in src/http/include/icy/http/cookie.h:80
Sets the name of the cookie.
getName
const inline
inline const std::string & getName() constDefined in src/http/include/icy/http/cookie.h:83
Returns the name of the cookie.
setValue
void setValue(const std::string & value)Defined in src/http/include/icy/http/cookie.h:93
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().
getValue
const inline
inline const std::string & getValue() constDefined in src/http/include/icy/http/cookie.h:96
Returns the value of the cookie.
setComment
void setComment(const std::string & comment)Defined in src/http/include/icy/http/cookie.h:101
Sets the comment for the cookie.
Comments are only supported for version 1 cookies.
getComment
const inline
inline const std::string & getComment() constDefined in src/http/include/icy/http/cookie.h:104
Returns the comment for the cookie.
setDomain
void setDomain(const std::string & domain)Defined in src/http/include/icy/http/cookie.h:107
Sets the domain for the cookie.
getDomain
const inline
inline const std::string & getDomain() constDefined in src/http/include/icy/http/cookie.h:110
Returns the domain for the cookie.
setPath
void setPath(const std::string & path)Defined in src/http/include/icy/http/cookie.h:113
Sets the path for the cookie.
getPath
const inline
inline const std::string & getPath() constDefined in src/http/include/icy/http/cookie.h:116
Returns the path for the cookie.
setSecure
void setSecure(bool secure)Defined in src/http/include/icy/http/cookie.h:120
Sets the value of the secure flag for the cookie.
getSecure
const inline
inline bool getSecure() constDefined in src/http/include/icy/http/cookie.h:124
Returns the value of the secure flag for the cookie.
setMaxAge
void setMaxAge(int maxAge)Defined in src/http/include/icy/http/cookie.h:134
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.
getMaxAge
const inline
inline int getMaxAge() constDefined in src/http/include/icy/http/cookie.h:138
Returns the maximum age in seconds for the cookie.
setHttpOnly
void setHttpOnly(bool flag = true)Defined in src/http/include/icy/http/cookie.h:141
Sets the HttpOnly flag for the cookie.
getHttpOnly
const inline
inline bool getHttpOnly() constDefined in src/http/include/icy/http/cookie.h:144
Returns true if the cookie's HttpOnly flag is set.
toString
const
std::string toString() constDefined in src/http/include/icy/http/cookie.h:148
Returns a std::string representation of the cookie, suitable for use in a Set-Cookie header.
Public Static Methods
| 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. |
escape
static
static std::string escape(std::string_view str)Defined in src/http/include/icy/http/cookie.h:154
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.
unescape
static
static std::string unescape(std::string_view str)Defined in src/http/include/icy/http/cookie.h:159
Unescapes the given std::string by replacing all escape sequences in the form xx with the respective characters.
Private Attributes
| 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 |
_version
int _versionDefined in src/http/include/icy/http/cookie.h:162
_name
std::string _nameDefined in src/http/include/icy/http/cookie.h:163
_value
std::string _valueDefined in src/http/include/icy/http/cookie.h:164
_comment
std::string _commentDefined in src/http/include/icy/http/cookie.h:165
_domain
std::string _domainDefined in src/http/include/icy/http/cookie.h:166
_path
std::string _pathDefined in src/http/include/icy/http/cookie.h:167
_secure
bool _secureDefined in src/http/include/icy/http/cookie.h:168
_maxAge
int _maxAgeDefined in src/http/include/icy/http/cookie.h:169
_httpOnly
bool _httpOnly