diff options
author | Michael BrĂ¼ning <michael.bruning@digia.com> | 2012-11-23 21:26:36 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-26 17:33:37 +0100 |
commit | 3279ed584ec132b305ef2079b22952fc62511b04 (patch) | |
tree | bbb724f64b2f47e02e2c163db0c3c6fc9a125e81 | |
parent | 1c818c34eacd746eb718a4e4f1e60a16f37e0c65 (diff) |
Only allow caching for HTTP GET and HEAD requests.
Added a method to QNetworkReplyHttpImplPrivate to check whether the
HTTP operation used in the current request allows for caching. This
should only be the case if the operation is GET or HEAD. The response
to all other request are not really cacheable and should be disallowed
from caching.
Change-Id: I7c31bae42814d157a800d43565e5cb9adfb879f7
Task-number: QTBUG-28035
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Reviewed-by: Peter Hartmann <phartmann@rim.com>
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 9 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl_p.h | 1 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 1cb6065a66..9409006abe 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1000,7 +1000,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) QByteDataBuffer pendingDownloadDataCopy = pendingDownloadData; pendingDownloadData.clear(); - if (cacheEnabled && !cacheSaveDevice) { + if (cacheEnabled && isCachingAllowed() && !cacheSaveDevice) { initCacheSaveDevice(); } @@ -1170,7 +1170,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceive if (!q->isOpen()) return; - if (cacheEnabled && bytesReceived == bytesTotal) { + if (cacheEnabled && isCachingAllowed() && bytesReceived == bytesTotal) { // Write everything in one go if we use a download buffer. might be more performant. initCacheSaveDevice(); // need to check again if cache enabled and device exists @@ -2027,6 +2027,11 @@ void QNetworkReplyHttpImplPrivate::setCachingEnabled(bool enable) } } +bool QNetworkReplyHttpImplPrivate::isCachingAllowed() const +{ + return operation == QNetworkAccessManager::GetOperation || operation == QNetworkAccessManager::HeadOperation; +} + void QNetworkReplyHttpImplPrivate::completeCacheSave() { if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) { diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h index 81393c2af0..956d5c207f 100644 --- a/src/network/access/qnetworkreplyhttpimpl_p.h +++ b/src/network/access/qnetworkreplyhttpimpl_p.h @@ -214,6 +214,7 @@ public: void completeCacheSave(); void setCachingEnabled(bool enable); bool isCachingEnabled() const; + bool isCachingAllowed() const; void initCacheSaveDevice(); QIODevice *cacheLoadDevice; bool loadingFromCache; |