summaryrefslogtreecommitdiff
path: root/src/storage/response.cpp
blob: cdaf33e4e419601ebf5e781803bc51ccbd4176e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <mbgl/storage/response.hpp>

#include <chrono>

namespace mbgl {

int64_t Response::parseCacheControl(const char *value) {
    if (value) {
        uint64_t 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 -1;
}

}