diff options
Diffstat (limited to 'src/network/access/qnetworkaccesshttpbackend.cpp')
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend.cpp | 24 |
1 files changed, 11 insertions, 13 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: |