diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-04-25 02:14:04 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-04-25 02:14:04 +0200 |
commit | 50d2f90b32782c0712a59eed16f7b0b2778dc7ab (patch) | |
tree | 7df91c77e152b6ce74d70ddd8f287d5b6521b476 /src/networkaccessmanager.cpp | |
parent | Network Access Manager, first improvements (diff) | |
download | rekonq-50d2f90b32782c0712a59eed16f7b0b2778dc7ab.tar.xz |
Various changes
- moved updateCOnfiguration slot to Application class from MainWindow (its right place)
- loaded conf out of ctor (this will increase boot speed, but could in theory let rekonq fails on first load. We'll see..)
- set accept-language (raw) header. RFC 2626, section 14. Choose your preferred language.
- Try fixing CacheControl values (rekonq seems work quite well offline, now)
Diffstat (limited to 'src/networkaccessmanager.cpp')
-rw-r--r-- | src/networkaccessmanager.cpp | 65 |
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); } |