From f0a7c45064c3ce3f509b1c2035fcaa07ccc35a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 1 Aug 2017 18:00:48 +0200 Subject: [core] finish must-revalidate support --- include/mbgl/storage/resource.hpp | 1 + include/mbgl/storage/response.hpp | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'include/mbgl') diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp index 7e9ced8049..5d44f4869f 100644 --- a/include/mbgl/storage/resource.hpp +++ b/include/mbgl/storage/resource.hpp @@ -68,6 +68,7 @@ public: optional priorModified = {}; optional priorExpires = {}; optional priorEtag = {}; + std::shared_ptr priorData; }; } // namespace mbgl diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp index 32fe4e0c8a..711f008e83 100644 --- a/include/mbgl/storage/response.hpp +++ b/include/mbgl/storage/response.hpp @@ -27,6 +27,10 @@ public: // This is set to true for 304 Not Modified responses. bool notModified = false; + // This is set to true when the server requested that no expired resources be used by + // specifying "Cache-Control: must-revalidate". + bool mustRevalidate = false; + // The actual data of the response. Present only for non-error, non-notModified responses. std::shared_ptr data; @@ -37,6 +41,12 @@ public: bool isFresh() const { return expires ? *expires > util::now() : !error; } + + // Indicates whether we are allowed to use this response according to HTTP caching rules. + // It may or may not be stale. + bool isUsable() const { + return !mustRevalidate || (expires && *expires > util::now()); + } }; class Response::Error { -- cgit v1.2.1