summaryrefslogtreecommitdiff
path: root/platform/default
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-09-02 16:40:41 +0200
committerIvo van Dongen <info@ivovandongen.nl>2016-09-13 14:21:38 +0200
commitdc4659b4a80cd6cfcce5db75b0648bbd4eb14b55 (patch)
treeac8790e226de6b1f7318c9c99b42aedf97389c6c /platform/default
parent0839df6a7aa2a27784b6d43187ef839d5a9cb4c3 (diff)
downloadqtlocation-mapboxgl-dc4659b4a80cd6cfcce5db75b0648bbd4eb14b55.tar.gz
[linux] HTTPFileSource - rate limit
Diffstat (limited to 'platform/default')
-rw-r--r--platform/default/http_file_source.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/platform/default/http_file_source.cpp b/platform/default/http_file_source.cpp
index 17e06a6c0f..ce6987fbdd 100644
--- a/platform/default/http_file_source.cpp
+++ b/platform/default/http_file_source.cpp
@@ -4,6 +4,7 @@
#include <mbgl/platform/log.hpp>
#include <mbgl/util/util.hpp>
+#include <mbgl/util/optional.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/timer.hpp>
@@ -80,6 +81,9 @@ private:
std::shared_ptr<std::string> data;
std::unique_ptr<Response> response;
+ optional<std::string> retryAfter;
+ optional<std::string> xRateLimitReset;
+
CURL *handle = nullptr;
curl_slist *headers = nullptr;
@@ -325,6 +329,10 @@ size_t HTTPRequest::headerCallback(char *const buffer, const size_t size, const
} else if ((begin = headerMatches("expires: ", buffer, length)) != std::string::npos) {
const std::string value { buffer + begin, length - begin - 2 }; // remove \r\n
baton->response->expires = Timestamp{ Seconds(curl_getdate(value.c_str(), nullptr)) };
+ } else if ((begin = headerMatches("retry-after: ", buffer, length)) != std::string::npos) {
+ baton->retryAfter = std::string(buffer + begin, length - begin - 2); // remove \r\n
+ } else if ((begin = headerMatches("x-rate-limit-reset: ", buffer, length)) != std::string::npos) {
+ baton->xRateLimitReset = std::string(buffer + begin, length - begin - 2); // remove \r\n
}
return length;
@@ -372,6 +380,10 @@ void HTTPRequest::handleResult(CURLcode code) {
} else if (responseCode == 404) {
response->error =
std::make_unique<Error>(Error::Reason::NotFound, "HTTP status code 404");
+ } else if (responseCode == 429) {
+ response->error =
+ std::make_unique<Error>(Error::Reason::RateLimit, "HTTP status code 429",
+ http::parseRetryHeaders(retryAfter, xRateLimitReset));
} else if (responseCode >= 500 && responseCode < 600) {
response->error =
std::make_unique<Error>(Error::Reason::Server, std::string{ "HTTP status code " } +