diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-05 16:52:07 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2016-02-10 15:40:20 -0800 |
commit | e9302c797f68c7e48b908b87b126045c8c5e5209 (patch) | |
tree | 044441cdb82ed8752401c43ead9e84018b067fbd /platform | |
parent | 7eb1a91c4e5134ecfbfb91b61a6622be40478af5 (diff) | |
download | qtlocation-mapboxgl-e9302c797f68c7e48b908b87b126045c8c5e5209.tar.gz |
[all] Don't interpret 404s on non-tile resources as "no content"
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/src/http_request_android.cpp | 2 | ||||
-rw-r--r-- | platform/darwin/http_request_nsurl.mm | 2 | ||||
-rw-r--r-- | platform/default/http_request_curl.cpp | 2 | ||||
-rw-r--r-- | platform/default/mbgl/storage/offline_database.cpp | 12 |
4 files changed, 12 insertions, 6 deletions
diff --git a/platform/android/src/http_request_android.cpp b/platform/android/src/http_request_android.cpp index 105ba5860c..023e0cde97 100644 --- a/platform/android/src/http_request_android.cpp +++ b/platform/android/src/http_request_android.cpp @@ -205,6 +205,8 @@ void HTTPAndroidRequest::onResponse(JNIEnv* env, int code, jstring /* message */ response->data = std::make_shared<std::string>(reinterpret_cast<char*>(bodyData), env->GetArrayLength(body)); env->ReleaseByteArrayElements(body, bodyData, JNI_ABORT); } + } else if (code == 204 || (code == 404 && resource.kind == Resource::Kind::Tile)) { + response->noContent = true; } else if (code == 304) { response->notModified = true; } else if (code == 404) { diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index 890e347afc..bc368f8724 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -217,6 +217,8 @@ void HTTPNSURLRequest::handleResult(NSData *data, NSURLResponse *res, NSError *e if (responseCode == 200) { response->data = std::make_shared<std::string>((const char *)[data bytes], [data length]); + } else if (responseCode == 204 || (responseCode == 404 && resource.kind == Resource::Kind::Tile)) { + response->noContent = true; } else if (responseCode == 304) { response->notModified = true; } else if (responseCode == 404) { diff --git a/platform/default/http_request_curl.cpp b/platform/default/http_request_curl.cpp index 660da4c43e..5b092573c6 100644 --- a/platform/default/http_request_curl.cpp +++ b/platform/default/http_request_curl.cpp @@ -515,6 +515,8 @@ void HTTPCURLRequest::handleResult(CURLcode code) { } else { response->data = std::make_shared<std::string>(); } + } else if (responseCode == 204 || (responseCode == 404 && resource.kind == Resource::Kind::Tile)) { + response->noContent = true; } else if (responseCode == 304) { response->notModified = true; } else if (responseCode == 404) { diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index cd0f88b7fe..67fcc435c6 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -101,8 +101,8 @@ optional<Response> OfflineDatabase::get(const Resource& resource) { } void OfflineDatabase::put(const Resource& resource, const Response& response) { - // Except for 404s, don't store errors in the cache. - if (response.error && response.error->reason != Response::Error::Reason::NotFound) { + // Don't store errors in the cache. + if (response.error) { return; } @@ -135,7 +135,7 @@ optional<Response> OfflineDatabase::getResource(const Resource& resource) { optional<std::string> data = stmt.get<optional<std::string>>(3); if (!data) { - response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound); + response.noContent = true; } else if (stmt.get<int>(4)) { response.data = std::make_shared<std::string>(util::decompress(*data)); } else { @@ -170,7 +170,7 @@ void OfflineDatabase::putResource(const Resource& resource, const Response& resp std::string data; - if (response.error) { // Can only be NotFound + if (response.noContent) { stmt.bind(7 /* data */, nullptr); stmt.bind(8 /* compressed */, false); } else { @@ -218,7 +218,7 @@ optional<Response> OfflineDatabase::getTile(const Resource::TileData& tile) { optional<std::string> data = stmt.get<optional<std::string>>(3); if (!data) { - response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound); + response.noContent = true; } else if (stmt.get<int>(4)) { response.data = std::make_shared<std::string>(util::decompress(*data)); } else { @@ -276,7 +276,7 @@ void OfflineDatabase::putTile(const Resource::TileData& tile, const Response& re std::string data; - if (response.error) { // Can only be NotFound + if (response.noContent) { stmt2.bind(10 /* data */, nullptr); stmt2.bind(11 /* compressed */, false); } else { |