diff options
author | Ivo van Dongen <info@ivovandongen.nl> | 2016-09-02 15:24:34 +0200 |
---|---|---|
committer | Ivo van Dongen <info@ivovandongen.nl> | 2016-09-13 14:21:37 +0200 |
commit | 0839df6a7aa2a27784b6d43187ef839d5a9cb4c3 (patch) | |
tree | 9fa57c62fa52c460c09ddf158dc32bb2d8c4a68c /platform/qt/src/http_request.cpp | |
parent | c04e79ae4877c9c47850f8221e192d99d804a15e (diff) | |
download | qtlocation-mapboxgl-0839df6a7aa2a27784b6d43187ef839d5a9cb4c3.tar.gz |
[qt] HttpFileSource - rate limit
Diffstat (limited to 'platform/qt/src/http_request.cpp')
-rw-r--r-- | platform/qt/src/http_request.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/platform/qt/src/http_request.cpp b/platform/qt/src/http_request.cpp index ac7d969e36..e19316fe2f 100644 --- a/platform/qt/src/http_request.cpp +++ b/platform/qt/src/http_request.cpp @@ -3,6 +3,7 @@ #include <mbgl/storage/response.hpp> #include <mbgl/util/chrono.hpp> +#include <mbgl/util/optional.hpp> #include <mbgl/util/http_header.hpp> #include <mbgl/util/string.hpp> @@ -68,6 +69,8 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) } QPair<QByteArray, QByteArray> line; + optional<std::string> retryAfter; + optional<std::string> xRateLimitReset; foreach(line, reply->rawHeaderPairs()) { QString header = QString(line.first).toLower(); @@ -79,6 +82,10 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) response.expires = http::CacheControl::parse(line.second.constData()).toTimePoint(); } else if (header == "expires") { response.expires = util::parseTimestamp(line.second.constData()); + } else if (header == "retry-after") { + retryAfter = std::string(line.second.constData(), line.second.size()); + } else if (header == "x-rate-limit-reset") { + xRateLimitReset = std::string(line.second.constData(), line.second.size()); } } @@ -109,6 +116,11 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply) } break; } + case 429: + response.error = std::make_unique<Error>( + Error::Reason::RateLimit, "HTTP status code 429", + http::parseRetryHeaders(retryAfter, xRateLimitReset)); + break; default: Response::Error::Reason reason = (responseCode >= 500 && responseCode < 600) ? Error::Reason::Server : Error::Reason::Other; |