summaryrefslogtreecommitdiff
path: root/src/networkaccessmanager.cpp
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-04-25 02:37:55 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-04-25 02:37:55 +0200
commita1e2bbeced79c46d7ee0f4c96c79ff3f23298f6d (patch)
treefd008b480ad17ccfa04ec087d8e67ca99190533d /src/networkaccessmanager.cpp
parentFixing new tab action position (diff)
parentFix error pages show (diff)
downloadrekonq-a1e2bbeced79c46d7ee0f4c96c79ff3f23298f6d.tar.xz
Merge branch 'NetworkRequestImprovements'
Diffstat (limited to 'src/networkaccessmanager.cpp')
-rw-r--r--src/networkaccessmanager.cpp70
1 files changed, 41 insertions, 29 deletions
diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp
index 99337206..15a71317 100644
--- a/src/networkaccessmanager.cpp
+++ b/src/networkaccessmanager.cpp
@@ -36,53 +36,65 @@
// KDE Includes
#include <KDebug>
+#include <KLocale>
+#include <KProtocolManager>
+
+// Defines
+#define QL1S(x) QLatin1String(x)
NetworkAccessManager::NetworkAccessManager(QObject *parent)
: AccessManager(parent)
- , _parentPage( qobject_cast<WebPage *>(parent) )
{
+ QString c = KGlobal::locale()->country();
+ if(c == QL1S("C"))
+ c = QL1S("en_US");
+ if(c != QL1S("en_US"))
+ c.append( QL1S(", en_US") );
+
+ _acceptLanguage = c.toLatin1();
}
-QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
+QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
+ WebPage *parentPage = qobject_cast<WebPage *>( parent() );
+
QNetworkReply *reply = 0;
- switch(op)
+ QNetworkRequest req = request;
+ req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
+ req.setRawHeader("Accept-Language", _acceptLanguage);
+
+ KIO::CacheControl cc = KProtocolManager::cacheControl();
+ switch(cc)
{
- case QNetworkAccessManager::HeadOperation:
- kDebug() << "HEAD OPERATION";
-// if(outgoingData)
-// {
-// QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024);
-// kDebug() << outgoingDataByteArray;
-// }
- break;
-
- case QNetworkAccessManager::GetOperation:
- kDebug() << "GET OPERATION";
- reply = Application::adblockManager()->block(req, _parentPage);
- if (reply)
- return reply;
- break;
-
- case QNetworkAccessManager::PutOperation:
- kDebug() << "PUT OPERATION";
- break;
-
- case QNetworkAccessManager::PostOperation:
- kDebug() << "POST OPERATION";
+ case KIO::CC_CacheOnly: // Fail request if not in cache.
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
break;
-
- case QNetworkAccessManager::DeleteOperation:
- kDebug() << "DELETE OPERATION";
+
+ case KIO::CC_Refresh: // Always validate cached entry with remote site.
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork);
break;
+ case KIO::CC_Reload: // Always fetch from remote site
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
+ break;
+
+ case KIO::CC_Cache: // Use cached entry if available.
+ case KIO::CC_Verify: // Validate cached entry with remote site if expired.
default:
- kDebug() << "UNKNOWN OPERATION";
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
break;
}
+
+
+ if( op == QNetworkAccessManager::GetOperation )
+ {
+ reply = Application::adblockManager()->block(req, parentPage);
+ if (reply)
+ return reply;
+ }
return AccessManager::createRequest(op,req,outgoingData);
}