summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-07-15 12:56:57 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2009-07-21 10:07:07 (GMT)
commit42e469bc5edcc6dee2401a104bd30de6b4be54fe (patch)
treecaa9acef985e50c8fd4a2c7f52ed7a1977bc3d6b
parent08834e4f7af8c1a4fe34ccfbbb8d2c973e91eb48 (diff)
downloadQt-42e469bc5edcc6dee2401a104bd30de6b4be54fe.zip
Qt-42e469bc5edcc6dee2401a104bd30de6b4be54fe.tar.gz
Qt-42e469bc5edcc6dee2401a104bd30de6b4be54fe.tar.bz2
QNAM: Proper loading of meta data when having AlwaysCache mode
Properly load the raw headers and properly handle the redirection when having a network cache in AlwaysCache mode (equals the offline mode in web browser). Task-number: 256240 Reviewed-by: Thiago Macieira
-rw-r--r--src/network/access/qnetworkaccesscachebackend.cpp14
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp10
2 files changed, 24 insertions, 0 deletions
diff --git a/src/network/access/qnetworkaccesscachebackend.cpp b/src/network/access/qnetworkaccesscachebackend.cpp
index f46a50a..8571ba3 100644
--- a/src/network/access/qnetworkaccesscachebackend.cpp
+++ b/src/network/access/qnetworkaccesscachebackend.cpp
@@ -86,6 +86,20 @@ bool QNetworkAccessCacheBackend::sendCacheContents()
setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute));
setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true);
+ // set the raw headers
+ QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders();
+ QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(),
+ end = rawHeaders.constEnd();
+ for ( ; it != end; ++it)
+ setRawHeader(it->first, it->second);
+
+ // handle a possible redirect
+ QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirectionTarget.isValid()) {
+ setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
+ redirectionRequested(redirectionTarget.toUrl());
+ }
+
// signal we're open
metaDataChanged();
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 98944fd..4ec3a75 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -376,7 +376,17 @@ void QNetworkReplyImplPrivate::feed(const QByteArray &data)
QNetworkCacheMetaData metaData;
metaData.setUrl(url);
metaData = backend->fetchCacheMetaData(metaData);
+
+ // save the redirect request also in the cache
+ QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ if (redirectionTarget.isValid()) {
+ QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes();
+ attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
+ metaData.setAttributes(attributes);
+ }
+
cacheSaveDevice = networkCache->prepare(metaData);
+
if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
if (cacheSaveDevice && !cacheSaveDevice->isOpen())
qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- "