From a5562d345b212c722b3b0a9296b0ab9187959ddf Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 8 Apr 2011 15:08:05 +0200 Subject: [PATCH] HTTP caching internals: fix logic for PreferNetwork and PreferCache --- src/network/access/qnetworkreplyhttpimpl.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 3acbfff70f0..1d8605810c7 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -441,6 +441,11 @@ bool QNetworkReplyHttpImplPrivate::loadFromCacheIfAllowed(QHttpNetworkRequest &h httpRequest.setHeaderField("If-Modified-Since", QNetworkHeadersPrivate::toHttpDate(lastModified)); if (CacheLoadControlAttribute == QNetworkRequest::PreferNetwork) { + // PreferNetwork == send request with "If-None-Match" and "If-Modified-Since" header, + // which will return a 304 Not Modifed if resource has not been changed. + // We might read from cache later, if receiving a 304. + return false; + } else if (CacheLoadControlAttribute == QNetworkRequest::PreferCache) { it = cacheHeaders.findRawHeader("Cache-Control"); if (it != cacheHeaders.rawHeaders.constEnd()) { QHash cacheControl = parseHttpOptionHeader(it->second); @@ -1422,7 +1427,7 @@ QNetworkCacheMetaData QNetworkReplyHttpImplPrivate::fetchCacheMetaData(const QNe attributes.insert(QNetworkRequest::HttpStatusCodeAttribute, statusCode); attributes.insert(QNetworkRequest::HttpReasonPhraseAttribute, reasonPhrase); } else { - // this is a redirection, keep the attributes intact + // this is the server telling us the resource has not changed, keep the attributes intact attributes = oldMetaData.attributes(); } metaData.setAttributes(attributes);