summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@trolltech.com>2009-05-12 15:58:27 (GMT)
committerPeter Hartmann <peter.hartmann@trolltech.com>2009-05-13 14:02:50 (GMT)
commit1c22d96f15d46c222bf5f1720e3e49e202a6c941 (patch)
tree5a0ce38c74dc7a16dc9b435b57863dca5ff3b46c /src
parent62677589caf8b2f45f369cfc9df30ded323c4155 (diff)
downloadQt-1c22d96f15d46c222bf5f1720e3e49e202a6c941.zip
Qt-1c22d96f15d46c222bf5f1720e3e49e202a6c941.tar.gz
Qt-1c22d96f15d46c222bf5f1720e3e49e202a6c941.tar.bz2
HTTP backend / network cache: only cache responses to GET by default
responses to POST might be cacheable, but are not cacheable by default; responses to PUT or DELETE are never cacheable. Reviewed-by: Thiago Macieira Task-number: 252281
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp42
1 files changed, 30 insertions, 12 deletions
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index a52b5a0..f214699 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -1036,21 +1036,39 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo
if (it != cacheHeaders.rawHeaders.constEnd())
metaData.setLastModified(QNetworkHeadersPrivate::fromHttpDate(it->second));
- bool canDiskCache = true; // Everything defaults to being cacheable on disk
-
- // 14.32
- // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client
- // had sent "Cache-Control: no-cache".
- it = cacheHeaders.findRawHeader("pragma");
- if (it != cacheHeaders.rawHeaders.constEnd()
- && it->second == "no-cache")
- canDiskCache = false;
+ bool canDiskCache;
+ // only cache GET replies by default, all other replies (POST, PUT, DELETE)
+ // are not cacheable by default (according to RFC 2616 section 9)
+ if (httpReply->request().operation() == QHttpNetworkRequest::Get) {
+
+ canDiskCache = true;
+ // 14.32
+ // HTTP/1.1 caches SHOULD treat "Pragma: no-cache" as if the client
+ // had sent "Cache-Control: no-cache".
+ it = cacheHeaders.findRawHeader("pragma");
+ if (it != cacheHeaders.rawHeaders.constEnd()
+ && it->second == "no-cache")
+ canDiskCache = false;
+
+ // HTTP/1.1. Check the Cache-Control header
+ if (cacheControl.contains("no-cache"))
+ canDiskCache = false;
+ else if (cacheControl.contains("no-store"))
+ canDiskCache = false;
+
+ // responses to POST might be cacheable
+ } else if (httpReply->request().operation() == QHttpNetworkRequest::Post) {
- // HTTP/1.1. Check the Cache-Control header
- if (cacheControl.contains("no-cache"))
canDiskCache = false;
- else if (cacheControl.contains("no-store"))
+ // some pages contain "expires:" and "cache-control: no-cache" field,
+ // so we only might cache POST requests if we get "cache-control: max-age ..."
+ if (cacheControl.contains("max-age"))
+ canDiskCache = true;
+
+ // responses to PUT and DELETE are not cacheable
+ } else {
canDiskCache = false;
+ }
metaData.setSaveToDisk(canDiskCache);
int statusCode = httpReply->statusCode();