Qt 4.8
|
The QNetworkCookie class holds one network cookie. More...
#include <qnetworkcookie.h>
Public Types | |
enum | RawForm { NameAndValueOnly, Full } |
This enum is used with the toRawForm() function to declare which form of a cookie shall be returned. More... | |
Public Functions | |
QString | domain () const |
Returns the domain this cookie is associated with. More... | |
QDateTime | expirationDate () const |
Returns the expiration date for this cookie. More... | |
bool | isHttpOnly () const |
Returns true if the "HttpOnly" flag is enabled for this cookie. More... | |
bool | isSecure () const |
Returns true if the "secure" option was specified in the cookie string, false otherwise. More... | |
bool | isSessionCookie () const |
Returns true if this cookie is a session cookie. More... | |
QByteArray | name () const |
Returns the name of this cookie. More... | |
bool | operator!= (const QNetworkCookie &other) const |
Returns true if this cookie is not equal to other. More... | |
QNetworkCookie & | operator= (const QNetworkCookie &other) |
Copies the contents of the QNetworkCookie object other to this object. More... | |
bool | operator== (const QNetworkCookie &other) const |
Returns true if this cookie is equal to other. More... | |
QString | path () const |
Returns the path associated with this cookie. More... | |
QNetworkCookie (const QByteArray &name=QByteArray(), const QByteArray &value=QByteArray()) | |
Create a new QNetworkCookie object, initializing the cookie name to name and its value to value. More... | |
QNetworkCookie (const QNetworkCookie &other) | |
Creates a new QNetworkCookie object by copying the contents of other. More... | |
void | setDomain (const QString &domain) |
Sets the domain associated with this cookie to be domain. More... | |
void | setExpirationDate (const QDateTime &date) |
Sets the expiration date of this cookie to date. More... | |
void | setHttpOnly (bool enable) |
Sets this cookie's "HttpOnly" flag to enable. More... | |
void | setName (const QByteArray &cookieName) |
Sets the name of this cookie to be cookieName. More... | |
void | setPath (const QString &path) |
Sets the path associated with this cookie to be path. More... | |
void | setSecure (bool enable) |
Sets the secure flag of this cookie to enable. More... | |
void | setValue (const QByteArray &value) |
Sets the value of this cookie to be value. More... | |
QByteArray | toRawForm (RawForm form=Full) const |
Returns the raw form of this QNetworkCookie. More... | |
QByteArray | value () const |
Returns this cookies value, as specified in the cookie string. More... | |
~QNetworkCookie () | |
Destroys this QNetworkCookie object. More... | |
Static Public Functions | |
static QList< QNetworkCookie > | parseCookies (const QByteArray &cookieString) |
Parses the cookie string cookieString as received from a server response in the "Set-Cookie:" header. More... | |
Properties | |
QSharedDataPointer< QNetworkCookiePrivate > | d |
Friends | |
class | QNetworkCookiePrivate |
The QNetworkCookie class holds one network cookie.
Cookies are small bits of information that stateless protocols like HTTP use to maintain some persistent information across requests.
A cookie is set by a remote server when it replies to a request and it expects the same cookie to be sent back when further requests are sent.
QNetworkCookie holds one such cookie as received from the network. A cookie has a name and a value, but those are opaque to the application (that is, the information stored in them has no meaning to the application). A cookie has an associated path name and domain, which indicate when the cookie should be sent again to the server.
A cookie can also have an expiration date, indicating its validity. If the expiration date is not present, the cookie is considered a "session cookie" and should be discarded when the application exits (or when its concept of session is over).
QNetworkCookie provides a way of parsing a cookie from the HTTP header format using the QNetworkCookie::parseCookies() function. However, when received in a QNetworkReply, the cookie is already parsed.
This class implements cookies as described by the Netscape Cookie Specification{initial cookie specification by Netscape}, which is somewhat similar to the RFC 2109 specification, plus the Mitigating Cross-site Scripting With HTTP-only Cookies {"HttpOnly" extension}. The more recent RFC 2965 specification (which uses the Set-Cookie2 header) is not supported.
Definition at line 62 of file qnetworkcookie.h.
This enum is used with the toRawForm() function to declare which form of a cookie shall be returned.
Note that only the Full form of the cookie can be parsed back into its original contents.
Enumerator | |
---|---|
NameAndValueOnly | |
Full |
Definition at line 65 of file qnetworkcookie.h.
QNetworkCookie::QNetworkCookie | ( | const QByteArray & | name = QByteArray() , |
const QByteArray & | value = QByteArray() |
||
) |
Create a new QNetworkCookie object, initializing the cookie name to name and its value to value.
A cookie is only valid if it has a name. However, the value is opaque to the application and being empty may have significance to the remote server.
Definition at line 109 of file qnetworkcookie.cpp.
QNetworkCookie::QNetworkCookie | ( | const QNetworkCookie & | other | ) |
Creates a new QNetworkCookie object by copying the contents of other.
Definition at line 123 of file qnetworkcookie.cpp.
QNetworkCookie::~QNetworkCookie | ( | ) |
QString QNetworkCookie::domain | ( | ) | const |
Returns the domain this cookie is associated with.
This corresponds to the "domain" field of the cookie string.
Note that the domain here may start with a dot, which is not a valid hostname. However, it means this cookie matches all hostnames ending with that domain name.
Definition at line 290 of file qnetworkcookie.cpp.
Referenced by QNetworkCookieJar::setCookiesFromUrl(), and setDomain().
QDateTime QNetworkCookie::expirationDate | ( | ) | const |
Returns the expiration date for this cookie.
If this cookie is a session cookie, the QDateTime returned will not be valid. If the date is in the past, this cookie has already expired and should not be sent again back to a remote server.
The expiration date corresponds to the parameters of the "expires" entry in the cookie string.
Definition at line 263 of file qnetworkcookie.cpp.
Referenced by QNetworkCookieJar::setCookiesFromUrl().
bool QNetworkCookie::isHttpOnly | ( | ) | const |
Returns true if the "HttpOnly" flag is enabled for this cookie.
A cookie that is "HttpOnly" is only set and retrieved by the network requests and replies; i.e., the HTTP protocol. It is not accessible from scripts running on browsers.
Definition at line 221 of file qnetworkcookie.cpp.
Referenced by toRawForm().
bool QNetworkCookie::isSecure | ( | ) | const |
Returns true if the "secure" option was specified in the cookie string, false otherwise.
Secure cookies may contain private information and should not be resent over unencrypted connections.
Definition at line 189 of file qnetworkcookie.cpp.
Referenced by toRawForm().
bool QNetworkCookie::isSessionCookie | ( | ) | const |
Returns true if this cookie is a session cookie.
A session cookie is a cookie which has no expiration date, which means it should be discarded when the application's concept of session is over (usually, when the application exits).
Definition at line 247 of file qnetworkcookie.cpp.
Referenced by QNetworkCookieJar::setCookiesFromUrl(), and toRawForm().
QByteArray QNetworkCookie::name | ( | ) | const |
Returns the name of this cookie.
The only mandatory field of a cookie is its name, without which it is not considered valid.
Definition at line 332 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine(), QNetworkCookie(), and QNetworkCookieJar::setCookiesFromUrl().
|
inline |
Returns true if this cookie is not equal to other.
Definition at line 75 of file qnetworkcookie.h.
QNetworkCookie & QNetworkCookie::operator= | ( | const QNetworkCookie & | other | ) |
Copies the contents of the QNetworkCookie object other to this object.
Definition at line 141 of file qnetworkcookie.cpp.
bool QNetworkCookie::operator== | ( | const QNetworkCookie & | other | ) | const |
Returns true if this cookie is equal to other.
This function only returns true if all fields of the cookie are the same.
However, in some contexts, two cookies of the same name could be considered equal.
Definition at line 167 of file qnetworkcookie.cpp.
|
static |
Parses the cookie string cookieString as received from a server response in the "Set-Cookie:" header.
If there's a parsing error, this function returns an empty list.
Since the HTTP header can set more than one cookie at the same time, this function returns a QList<QNetworkCookie>, one for each cookie that is parsed.
Definition at line 944 of file qnetworkcookie.cpp.
Referenced by parseCookieHeader(), and parseHeaderValue().
QString QNetworkCookie::path | ( | ) | const |
Returns the path associated with this cookie.
This corresponds to the "path" field of the cookie string.
Definition at line 311 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine(), QNetworkCookieJar::setCookiesFromUrl(), and setPath().
void QNetworkCookie::setDomain | ( | const QString & | domain | ) |
Sets the domain associated with this cookie to be domain.
Definition at line 300 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine(), and QNetworkCookieJar::setCookiesFromUrl().
void QNetworkCookie::setExpirationDate | ( | const QDateTime & | date | ) |
Sets the expiration date of this cookie to date.
Setting an invalid expiration date to this cookie will mean it's a session cookie.
Definition at line 275 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine().
void QNetworkCookie::setHttpOnly | ( | bool | enable | ) |
Sets this cookie's "HttpOnly" flag to enable.
Definition at line 234 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine().
void QNetworkCookie::setName | ( | const QByteArray & | cookieName | ) |
Sets the name of this cookie to be cookieName.
Note that setting a cookie name to an empty QByteArray will make this cookie invalid.
Definition at line 344 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine().
void QNetworkCookie::setPath | ( | const QString & | path | ) |
Sets the path associated with this cookie to be path.
Definition at line 321 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine(), and QNetworkCookieJar::setCookiesFromUrl().
void QNetworkCookie::setSecure | ( | bool | enable | ) |
Sets the secure flag of this cookie to enable.
Secure cookies may contain private information and should not be resent over unencrypted connections.
Definition at line 202 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine().
void QNetworkCookie::setValue | ( | const QByteArray & | value | ) |
Sets the value of this cookie to be value.
Definition at line 368 of file qnetworkcookie.cpp.
Referenced by QNetworkCookiePrivate::parseSetCookieHeaderLine().
QByteArray QNetworkCookie::toRawForm | ( | RawForm | form = Full | ) | const |
Returns the raw form of this QNetworkCookie.
The QByteArray returned by this function is suitable for an HTTP header, either in a server response (the Set-Cookie header) or the client request (the Cookie header). You can choose from one of two formats, using form.
Definition at line 496 of file qnetworkcookie.cpp.
Referenced by headerValue(), and operator<<().
QByteArray QNetworkCookie::value | ( | ) | const |
Returns this cookies value, as specified in the cookie string.
Note that a cookie is still valid if its value is empty.
Cookie name-value pairs are considered opaque to the application: that is, their values don't mean anything.
Definition at line 358 of file qnetworkcookie.cpp.
Referenced by QNetworkCookie(), setValue(), and toRawForm().
|
friend |
Definition at line 105 of file qnetworkcookie.h.
|
private |
Definition at line 104 of file qnetworkcookie.h.
Referenced by domain(), expirationDate(), isHttpOnly(), isSecure(), isSessionCookie(), name(), operator=(), operator==(), parseDateString(), path(), QNetworkCookie(), setDomain(), setExpirationDate(), setHttpOnly(), setName(), setPath(), setSecure(), setValue(), toRawForm(), value(), and ~QNetworkCookie().