Commit b85cf342 authored by Dan Leinir Turthra Jensen's avatar Dan Leinir Turthra Jensen 🌈
Browse files

Only trust the expiration date if it's less than 24 hours

parent 8e164050
Pipeline #135444 passed with stage
in 2 minutes and 48 seconds
......@@ -133,7 +133,16 @@ QNetworkRequest KdePlatformDependent::addOAuthToRequest(const QNetworkRequest &r
for (const QString &endpoint : preferCacheEndpoints) {
if (notConstReq.url().endsWith(endpoint)) {
notConstReq.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
QNetworkCacheMetaData cacheMeta{m_accessManager->cache.metaData(notConstReq.url())};
if (cacheMeta.isValid()) {
// If the expiration date is valid, but longer than 24 hours, don't trust that things
// haven't changed and check first, otherwise just use the cached version to relieve
// server strain and reduce network traffic.
const QDateTime tomorrow{QDateTime::currentDateTime().addDays(1)};
if (cacheMeta.expirationDate().isValid() && cacheMeta.expirationDate() < tomorrow) {
notConstReq.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment