From ed429ebfc9920c3a0fc97170ff8df6d5520eefb9 Mon Sep 17 00:00:00 2001 From: "Jonas M. Gastal" Date: Wed, 11 Jan 2012 17:00:11 -0200 Subject: 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 Reviewed-by: Alexis Menard Reviewed-by: Lars Knoll Reviewed-by: Shane Kearns --- src/network/access/qnetworkcookie.cpp | 37 ++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/network/access/qnetworkcookie.cpp') 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 { @@ -171,6 +171,17 @@ bool QNetworkCookie::operator==(const QNetworkCookie &other) const d->comment == other.d->comment; } +/*! + 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 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) { -- cgit v1.2.3