[core] more robust max-age parsing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user