diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2011-04-04 11:28:20 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@nokia.com> | 2011-04-04 11:49:25 (GMT) |
commit | 12a0099dfb8242d0296ccef1a78d75327ff8fe03 (patch) | |
tree | bc13ab7cc62b17d5508341058238e633ae1ebcf8 /src/network | |
parent | 939d2e725c2c52f33097fcc50664c46d40c05b04 (diff) | |
download | Qt-12a0099dfb8242d0296ccef1a78d75327ff8fe03.zip Qt-12a0099dfb8242d0296ccef1a78d75327ff8fe03.tar.gz Qt-12a0099dfb8242d0296ccef1a78d75327ff8fe03.tar.bz2 |
HTTP backend: make cache validation method return bool
... rather than storing it in a bool reference.
Reviewed-by: Markus Goetz
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend.cpp | 24 | ||||
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend_p.h | 2 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index fd20b2a..84a899e 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -219,7 +219,7 @@ QNetworkAccessHttpBackend::~QNetworkAccessHttpBackend() 2) If we have a cache entry for this url populate headers so the server can return 304 3) Calculate if response_is_fresh and if so send the cache and set loadedFromCache to true */ -void QNetworkAccessHttpBackend::validateCache(QHttpNetworkRequest &httpRequest, bool &loadedFromCache) +bool QNetworkAccessHttpBackend::validateCache(QHttpNetworkRequest &httpRequest) { QNetworkRequest::CacheLoadControl CacheLoadControlAttribute = (QNetworkRequest::CacheLoadControl)request().attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt(); @@ -230,24 +230,24 @@ void QNetworkAccessHttpBackend::validateCache(QHttpNetworkRequest &httpRequest, httpRequest.setHeaderField("Cache-Control", "no-cache"); httpRequest.setHeaderField("Pragma", "no-cache"); } - return; + return false; } // The disk cache API does not currently support partial content retrieval. // That is why we don't use the disk cache for any such requests. if (request().hasRawHeader("Range")) - return; + return false; QAbstractNetworkCache *nc = networkCache(); if (!nc) - return; // no local cache + return false; // no local cache QNetworkCacheMetaData metaData = nc->metaData(url()); if (!metaData.isValid()) - return; // not in cache + return false; // not in cache if (!metaData.saveToDisk()) - return; + return false; QNetworkHeadersPrivate cacheHeaders; QNetworkHeadersPrivate::RawHeadersList::ConstIterator it; @@ -266,7 +266,7 @@ void QNetworkAccessHttpBackend::validateCache(QHttpNetworkRequest &httpRequest, if (it != cacheHeaders.rawHeaders.constEnd()) { QHash<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); if (cacheControl.contains("must-revalidate")) - return; + return false; } } @@ -338,14 +338,12 @@ void QNetworkAccessHttpBackend::validateCache(QHttpNetworkRequest &httpRequest, #endif if (!response_is_fresh) - return; + return false; - loadedFromCache = true; #if defined(QNETWORKACCESSHTTPBACKEND_DEBUG) qDebug() << "response_is_fresh" << CacheLoadControlAttribute; #endif - if (!sendCacheContents(metaData)) - loadedFromCache = false; + return sendCacheContents(metaData); } static QHttpNetworkRequest::Priority convert(const QNetworkRequest::Priority& prio) @@ -442,12 +440,12 @@ void QNetworkAccessHttpBackend::postRequest() switch (operation()) { case QNetworkAccessManager::GetOperation: httpRequest.setOperation(QHttpNetworkRequest::Get); - validateCache(httpRequest, loadedFromCache); + loadedFromCache = validateCache(httpRequest); break; case QNetworkAccessManager::HeadOperation: httpRequest.setOperation(QHttpNetworkRequest::Head); - validateCache(httpRequest, loadedFromCache); + loadedFromCache = validateCache(httpRequest); break; case QNetworkAccessManager::PostOperation: diff --git a/src/network/access/qnetworkaccesshttpbackend_p.h b/src/network/access/qnetworkaccesshttpbackend_p.h index 712dd2f..5e143eb 100644 --- a/src/network/access/qnetworkaccesshttpbackend_p.h +++ b/src/network/access/qnetworkaccesshttpbackend_p.h @@ -148,7 +148,7 @@ private: quint64 resumeOffset; - void validateCache(QHttpNetworkRequest &httpRequest, bool &loadedFromCache); + bool validateCache(QHttpNetworkRequest &httpRequest); void invalidateCache(); void postRequest(); void readFromHttp(); |