diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-11-19 21:47:15 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-11-20 14:39:44 +0100 |
commit | b5f7cafab45471bd7d714fb2972e33603a4baaae (patch) | |
tree | aff2a9125627105e1bd977105df5175f332b89dc /src/mbgl/storage | |
parent | 94e2d8a02c321380e650d055e7e7d6d6ed1c529d (diff) | |
download | qtlocation-mapboxgl-b5f7cafab45471bd7d714fb2972e33603a4baaae.tar.gz |
[core] more robust max-age parsing
Diffstat (limited to 'src/mbgl/storage')
-rw-r--r-- | src/mbgl/storage/http_request_base.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/mbgl/storage/http_request_base.cpp b/src/mbgl/storage/http_request_base.cpp index 2da453ead8..f9e40c4f2b 100644 --- a/src/mbgl/storage/http_request_base.cpp +++ b/src/mbgl/storage/http_request_base.cpp @@ -1,18 +1,18 @@ #include <mbgl/storage/http_request_base.hpp> +#include <mbgl/util/http_header.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) { + const auto cacheControl = http::CacheControl::parse(value); + + if (cacheControl.maxAge) { return std::chrono::duration_cast<std::chrono::seconds>( std::chrono::system_clock::now().time_since_epoch()).count() + - seconds; + *cacheControl.maxAge; } } |