summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-10-26 17:07:10 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-10-26 18:37:51 +0200
commitc65f809651dccc742d4d549f4dedf794de8623fc (patch)
treeb35ea2ac1181b098405f586ec5596f13402c92c3 /src
parent75dec6ffac6f3e79e5a173cd8a3f98d374ed1c09 (diff)
downloadqtlocation-mapboxgl-c65f809651dccc742d4d549f4dedf794de8623fc.tar.gz
[core] Move parseCacheControl() up in the class hierarchy
Avoid duplicating it on all the ports.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/storage/http_request_base.cpp22
-rw-r--r--src/mbgl/storage/http_request_base.hpp2
2 files changed, 24 insertions, 0 deletions
diff --git a/src/mbgl/storage/http_request_base.cpp b/src/mbgl/storage/http_request_base.cpp
new file mode 100644
index 0000000000..2da453ead8
--- /dev/null
+++ b/src/mbgl/storage/http_request_base.cpp
@@ -0,0 +1,22 @@
+#include <mbgl/storage/http_request_base.hpp>
+
+#include <mbgl/util/chrono.hpp>
+
+namespace mbgl {
+
+int64_t HTTPRequestBase::parseCacheControl(const char *value) {
+ if (value) {
+ unsigned long long seconds = 0;
+ // TODO: cache-control may contain other information as well:
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
+ if (std::sscanf(value, "max-age=%llu", &seconds) == 1) {
+ return std::chrono::duration_cast<std::chrono::seconds>(
+ std::chrono::system_clock::now().time_since_epoch()).count() +
+ seconds;
+ }
+ }
+
+ return 0;
+}
+
+}
diff --git a/src/mbgl/storage/http_request_base.hpp b/src/mbgl/storage/http_request_base.hpp
index 508095e3c1..b28cb9fcc1 100644
--- a/src/mbgl/storage/http_request_base.hpp
+++ b/src/mbgl/storage/http_request_base.hpp
@@ -46,6 +46,8 @@ public:
virtual void retry() = 0;
protected:
+ static int64_t parseCacheControl(const char *value);
+
bool cancelled;
};