diff options
author | Peter Hartmann <peter.hartmann@nokia.com> | 2011-04-07 13:01:20 (GMT) |
---|---|---|
committer | Peter Hartmann <peter.hartmann@nokia.com> | 2011-04-07 13:11:27 (GMT) |
commit | e5d27e7aeac984e46f3aa8de20160cc00fc63155 (patch) | |
tree | e322565f110766f41af1f47428b6f65c7ec9c75d /src/network/access | |
parent | 7433709193db3e2e9adf4960ec9eceedcacc1721 (diff) | |
download | Qt-e5d27e7aeac984e46f3aa8de20160cc00fc63155.zip Qt-e5d27e7aeac984e46f3aa8de20160cc00fc63155.tar.gz Qt-e5d27e7aeac984e46f3aa8de20160cc00fc63155.tar.bz2 |
HTTP caching internals: fix logic for PreferNetwork and PreferCache
PreferNetwork means: send out a request and read from cache if it has
not been modified.
PreferCache means: load resource from cache if it has not expired yet.
This commit makes the cache behave according to the documentation.
Reviewed-by: Markus Goetz
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qnetworkaccesshttpbackend.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 0438fb5..4ac0a67 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -262,6 +262,11 @@ bool QNetworkAccessHttpBackend::loadFromCacheIfAllowed(QHttpNetworkRequest &http 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<QByteArray, QByteArray> cacheControl = parseHttpOptionHeader(it->second); @@ -1145,7 +1150,7 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo 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); |