From c04e79ae4877c9c47850f8221e192d99d804a15e Mon Sep 17 00:00:00 2001 From: Ivo van Dongen Date: Fri, 2 Sep 2016 14:05:46 +0200 Subject: [PATCH] [darwin] HttpFileSource - rate limit --- platform/darwin/src/http_file_source.mm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index a678b6e5c..caac2123d 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -10,6 +10,7 @@ #import #include +#include @interface MBGLBundleCanary : NSObject @end @@ -293,6 +294,22 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, } else if (responseCode == 404) { response.error = std::make_unique(Error::Reason::NotFound, "HTTP status code 404"); + } else if (responseCode == 429) { + //Get the standard header + optional retryAfter; + NSString *retryAfterHeader = headers[@"Retry-After"]; + if (retryAfterHeader) { + retryAfter = std::string([retryAfterHeader UTF8String]); + } + + //Fallback mapbox specific header + optional xRateLimitReset; + NSString *xReset = headers[@"x-rate-limit-reset"]; + if (xReset) { + xRateLimitReset = std::string([xReset UTF8String]); + } + + response.error = std::make_unique(Error::Reason::RateLimit, "HTTP status code 429", http::parseRetryHeaders(retryAfter, xRateLimitReset)); } else if (responseCode >= 500 && responseCode < 600) { response.error = std::make_unique(Error::Reason::Server, std::string{ "HTTP status code " } +