summaryrefslogtreecommitdiffstats
path: root/src/webclientserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webclientserver.cpp')
-rw-r--r--src/webclientserver.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/webclientserver.cpp b/src/webclientserver.cpp
index 44d120e..0e32717 100644
--- a/src/webclientserver.cpp
+++ b/src/webclientserver.cpp
@@ -72,7 +72,7 @@ void HttpRequest::parseText()
}
HttpResponse::HttpResponse()
-: contentType("text/html"), response304(false) { }
+: contentType("text/html"), response304(false), neverExpires(false) { }
void HttpResponse::setBody(const QByteArray &body)
{
@@ -99,6 +99,11 @@ void HttpResponse::set304Response()
response304 = true;
}
+void HttpResponse::setNeverExpires()
+{
+ neverExpires = true;
+}
+
bool HttpResponse::isHandled() const
{
return response304 || body.isEmpty() == false;
@@ -125,7 +130,21 @@ QByteArray HttpResponse::toText()
text+= "Set-Cookie: " + cookie + "\r\n";
}
- if (eTag.isEmpty() == false) {
+ // Support three different caching strategies:
+ // 1. Never-expires. Useful when content has a unique
+ // name based on e.g. a hash of the content. Allows the
+ // user agent to get the content once and then cache it
+ // forever.
+ // 2. Etag. The url for the content stays the same, the
+ // etag changes with content changes. Allows the user agent
+ // to ask if a spesific url as been updated, and then skip
+ // the content download if not.
+ // 3. no-cache. For dynamic content. Not cached by the user-agent
+ // and is re-downloaded on each request.
+ if (neverExpires) {
+ text += QByteArray("Cache-control: max-age: 99999 \r\n"); // or -1?
+ text += "eTag: 24 \r\n";
+ } else if (eTag.isEmpty() == false) {
text += "eTag: " + eTag + "\r\n";
} else {
text += QByteArray("Cace-control: no-cache \r\n");