[core] OnlineFileSource - rate limit

This commit is contained in:
Ivo van Dongen
2016-08-31 16:43:33 +02:00
parent fdaf26b2c0
commit 290bd07a92
15 changed files with 213 additions and 29 deletions

View File

@@ -28,6 +28,26 @@ CacheControl CacheControl::parse(const std::string& value) {
optional<Timestamp> CacheControl::toTimePoint() const {
return maxAge ? util::now() + Seconds(*maxAge) : optional<Timestamp>{};
}
optional<Timestamp> parseRetryHeaders(const optional<std::string>& retryAfter,
const optional<std::string>& xRateLimitReset) {
if (retryAfter) {
try {
auto secs = std::chrono::seconds(std::stoi(*retryAfter));
return std::chrono::time_point_cast<Seconds>(std::chrono::system_clock::now() + secs);
} catch (...) {
return util::parseTimestamp((*retryAfter).c_str());
}
} else if (xRateLimitReset) {
try {
return util::parseTimestamp(std::stoi(*xRateLimitReset));
} catch (...) {
return {};
}
}
return {};
}
} // namespace http
} // namespace mbgl