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>
This commit is contained in:
parent
1c818c34ea
commit
3279ed584e
@ -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) {
|
||||
|
@ -214,6 +214,7 @@ public:
|
||||
void completeCacheSave();
|
||||
void setCachingEnabled(bool enable);
|
||||
bool isCachingEnabled() const;
|
||||
bool isCachingAllowed() const;
|
||||
void initCacheSaveDevice();
|
||||
QIODevice *cacheLoadDevice;
|
||||
bool loadingFromCache;
|
||||
|
Loading…
Reference in New Issue
Block a user