blob: bafd18c3ce9aa25c6cbe2b24b707ea792a8789dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
From b85cf34298c274b5f16cb6c2aead7b87f0dabbb8 Mon Sep 17 00:00:00 2001
From: Dan Leinir Turthra Jensen <admin@leinir.dk>
Date: Wed, 9 Feb 2022 09:23:50 +0000
Subject: [PATCH] Only trust the expiration date if it's less than 24 hours
---
attica-kde/kdeplugin/kdeplatformdependent.cpp | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/attica-kde/kdeplugin/kdeplatformdependent.cpp b/attica-kde/kdeplugin/kdeplatformdependent.cpp
index fbc15ec4e..3cad87b36 100644
--- a/attica-kde/kdeplugin/kdeplatformdependent.cpp
+++ b/attica-kde/kdeplugin/kdeplatformdependent.cpp
@@ -125,6 +125,26 @@ QNetworkRequest KdePlatformDependent::addOAuthToRequest(const QNetworkRequest &r
const QString bearer = bearer_format.arg(token);
notConstReq.setRawHeader("Authorization", bearer.toUtf8());
}
+ notConstReq.setAttribute(QNetworkRequest::Http2AllowedAttribute, true);
+
+ // Add cache preference in a granular fashion (we will almost certainly want more of these, but...)
+ static const QStringList preferCacheEndpoints{QLatin1String{"/content/categories"}};
+ for (const QString &endpoint : preferCacheEndpoints) {
+ if (notConstReq.url().toString().endsWith(endpoint)) {
+ 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);
+ }
+ }
+ break;
+ }
+ }
+
return notConstReq;
}
--
GitLab
|