summaryrefslogtreecommitdiff
path: root/src/networkaccessmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/networkaccessmanager.cpp')
-rw-r--r--src/networkaccessmanager.cpp65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp
index 95b768d9..15a71317 100644
--- a/src/networkaccessmanager.cpp
+++ b/src/networkaccessmanager.cpp
@@ -36,54 +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 &request, QIODevice *outgoingData)
{
+ WebPage *parentPage = qobject_cast<WebPage *>( parent() );
+
QNetworkReply *reply = 0;
QNetworkRequest req = request;
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
- req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
-// if (!m_acceptLanguage.isEmpty())
-// req.setRawHeader("Accept-Language", m_acceptLanguage);
-
- switch(op)
+ req.setRawHeader("Accept-Language", _acceptLanguage);
+
+ KIO::CacheControl cc = KProtocolManager::cacheControl();
+ switch(cc)
{
- case QNetworkAccessManager::HeadOperation:
- kDebug() << "HEAD OPERATION";
- break;
-
- case QNetworkAccessManager::GetOperation:
- kDebug() << "GET OPERATION";
- reply = Application::adblockManager()->block(req, _parentPage);
- if (reply)
- return reply;
+ case KIO::CC_CacheOnly: // Fail request if not in cache.
+ req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
break;
-
- case QNetworkAccessManager::PutOperation:
- kDebug() << "PUT OPERATION";
- break;
-
- case QNetworkAccessManager::PostOperation:
- kDebug() << "POST OPERATION";
- 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);
}