diff options
author | Jonas M. Gastal <jgastal@profusion.mobi> | 2012-01-11 17:00:11 -0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-27 13:29:14 +0100 |
commit | ed429ebfc9920c3a0fc97170ff8df6d5520eefb9 (patch) | |
tree | de94dc0f0c79d9cc2423cf1955006d0432140645 /src/network/access/qnetworkcookie.cpp | |
parent | 1166ad8603fe4fbd1b008aaa7c043ee1078780a5 (diff) |
Gives QNetworkCookieJar a virtual API.
QNetworkCookieJar now has the following virtual methods:
virtual bool validateCookie(QNetworkCookie &cookie);
virtual bool insertCookie(const QNetworkCookie &cookie, const QUrl &url);
virtual bool updateCookie(const QNetworkCookie &cookie);
virtual void deleteCookie(const QNetworkCookie &cookie);
Their implementation is such that the behavior the class previously
had(in memory storage of the cookies) is mantained.
Task-number: QTBUG-23145
Change-Id: I1420894d31e8072eca6903c3c7ffd6f06205a257
Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
Reviewed-by: Alexis Menard <alexis.menard@openbossa.org>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Shane Kearns <ext-shane.2.kearns@nokia.com>
Diffstat (limited to 'src/network/access/qnetworkcookie.cpp')
-rw-r--r-- | src/network/access/qnetworkcookie.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index df7920de40..38e2ef093c 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -156,7 +156,7 @@ QNetworkCookie &QNetworkCookie::operator=(const QNetworkCookie &other) However, in some contexts, two cookies of the same name could be considered equal. - \sa operator!=() + \sa operator!=(), hasSameIdentifier() */ bool QNetworkCookie::operator==(const QNetworkCookie &other) const { @@ -172,6 +172,17 @@ bool QNetworkCookie::operator==(const QNetworkCookie &other) const } /*! + Returns true if this cookie has the same identifier tuple as \a other. + The identifier tuple is composed of the name, domain and path. + + \sa operator==() +*/ +bool QNetworkCookie::hasSameIdentifier(const QNetworkCookie &other) const +{ + return d->name == other.d->name && d->domain == other.d->domain && d->path == other.d->path; +} + +/*! Returns true if the "secure" option was specified in the cookie string, false otherwise. @@ -1042,6 +1053,30 @@ QList<QNetworkCookie> QNetworkCookiePrivate::parseSetCookieHeaderLine(const QByt return result; } +/*! + This functions normalizes the path and domain of the cookie if they were previously empty. +*/ +void QNetworkCookie::normalize(const QUrl &url) +{ + // don't do path checking. See http://bugreports.qt.nokia.com/browse/QTBUG-5815 + if (d->path.isEmpty()) { + QString pathAndFileName = url.path(); + QString defaultPath = pathAndFileName.left(pathAndFileName.lastIndexOf(QLatin1Char('/'))+1); + if (defaultPath.isEmpty()) + defaultPath = QLatin1Char('/'); + d->path = defaultPath; + } + + if (d->domain.isEmpty()) + d->domain = url.host(); + else if (!d->domain.startsWith(QLatin1Char('.'))) + // Ensure the domain starts with a dot if its field was not empty + // in the HTTP header. There are some servers that forget the + // leading dot and this is actually forbidden according to RFC 2109, + // but all browsers accept it anyway so we do that as well. + d->domain.prepend(QLatin1Char('.')); +} + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug s, const QNetworkCookie &cookie) { |