summaryrefslogtreecommitdiff
path: root/platform/darwin/src/http_file_source.mm
diff options
context:
space:
mode:
authorIvo van Dongen <info@ivovandongen.nl>2016-09-02 14:05:46 +0200
committerIvo van Dongen <info@ivovandongen.nl>2016-09-13 14:21:37 +0200
commitc04e79ae4877c9c47850f8221e192d99d804a15e (patch)
treec5b4b548fbf574d27bede335f285b99c02d67563 /platform/darwin/src/http_file_source.mm
parent290bd07a92d7103c67f606c1423785069fc9b776 (diff)
downloadqtlocation-mapboxgl-c04e79ae4877c9c47850f8221e192d99d804a15e.tar.gz
[darwin] HttpFileSource - rate limit
Diffstat (limited to 'platform/darwin/src/http_file_source.mm')
-rw-r--r--platform/darwin/src/http_file_source.mm17
1 files changed, 17 insertions, 0 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm
index a678b6e5cb..caac2123d8 100644
--- a/platform/darwin/src/http_file_source.mm
+++ b/platform/darwin/src/http_file_source.mm
@@ -10,6 +10,7 @@
#import <Foundation/Foundation.h>
#include <mutex>
+#include <chrono>
@interface MBGLBundleCanary : NSObject
@end
@@ -293,6 +294,22 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
} else if (responseCode == 404) {
response.error =
std::make_unique<Error>(Error::Reason::NotFound, "HTTP status code 404");
+ } else if (responseCode == 429) {
+ //Get the standard header
+ optional<std::string> retryAfter;
+ NSString *retryAfterHeader = headers[@"Retry-After"];
+ if (retryAfterHeader) {
+ retryAfter = std::string([retryAfterHeader UTF8String]);
+ }
+
+ //Fallback mapbox specific header
+ optional<std::string> xRateLimitReset;
+ NSString *xReset = headers[@"x-rate-limit-reset"];
+ if (xReset) {
+ xRateLimitReset = std::string([xReset UTF8String]);
+ }
+
+ 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 " } +