diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-08-31 16:43:33 +0200 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2016-09-13 14:21:37 +0200 |
commit | 290bd07a92d7103c67f606c1423785069fc9b776 (patch) | |
tree | 00fa0a654830f3cf239932f266e311cab6ebeb59 /src/mbgl/util/http_header.cpp | |
parent | fdaf26b2c02afa6042876962f92b1eaf0ada19bb (diff) | |
download | qtlocation-mapboxgl-290bd07a92d7103c67f606c1423785069fc9b776.tar.gz |
[core] OnlineFileSource - rate limit
Diffstat (limited to 'src/mbgl/util/http_header.cpp')
-rw-r--r-- | src/mbgl/util/http_header.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mbgl/util/http_header.cpp b/src/mbgl/util/http_header.cpp index dceb331a3f..e337d4c8ab 100644 --- a/src/mbgl/util/http_header.cpp +++ b/src/mbgl/util/http_header.cpp @@ -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 |