[core] unify URL prefix detection (asset:// and mapbox://)
This commit is contained in:
@@ -14,21 +14,13 @@
|
||||
#include <mbgl/util/async_task.hpp>
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
#include <mbgl/util/timer.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#pragma GCC diagnostic pop
|
||||
#include <mbgl/util/url.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace algo = boost::algorithm;
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class RequestBase;
|
||||
@@ -299,7 +291,7 @@ void OnlineFileSource::Impl::startRealRequest(OnlineFileRequestImpl& request) {
|
||||
reschedule(request);
|
||||
};
|
||||
|
||||
if (algo::starts_with(request.resource.url, "asset://")) {
|
||||
if (util::isAssetURL(request.resource.url)) {
|
||||
request.realRequest =
|
||||
assetContext->createRequest(request.resource.url, callback, assetRoot);
|
||||
} else {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <mbgl/util/texture_pool.hpp>
|
||||
#include <mbgl/util/exception.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -114,7 +115,8 @@ void MapContext::setStyleURL(const std::string& url) {
|
||||
styleRequest = nullptr;
|
||||
|
||||
if (res.error) {
|
||||
if (res.error->reason == Response::Error::Reason::NotFound && styleURL.find("mapbox://") == 0) {
|
||||
if (res.error->reason == Response::Error::Reason::NotFound &&
|
||||
util::mapbox::isMapboxURL(styleURL)) {
|
||||
Log::Error(Event::Setup, "style %s could not be found or is an incompatible legacy map or style", styleURL.c_str());
|
||||
} else {
|
||||
Log::Error(Event::Setup, "loading style failed: %s", res.error->message.c_str());
|
||||
|
||||
@@ -13,7 +13,7 @@ const std::string protocol = "mapbox://";
|
||||
const std::string baseURL = "https://api.mapbox.com/";
|
||||
|
||||
bool isMapboxURL(const std::string& url) {
|
||||
return url.compare(0, protocol.length(), protocol) == 0;
|
||||
return std::equal(protocol.begin(), protocol.end(), url.begin());
|
||||
}
|
||||
|
||||
std::vector<std::string> getMapboxURLPathname(const std::string& url) {
|
||||
|
||||
@@ -8,6 +8,8 @@ namespace mbgl {
|
||||
namespace util {
|
||||
namespace mapbox {
|
||||
|
||||
bool isMapboxURL(const std::string& url);
|
||||
|
||||
std::string normalizeSourceURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeStyleURL(const std::string& url, const std::string& accessToken);
|
||||
std::string normalizeSpriteURL(const std::string& url, const std::string& accessToken);
|
||||
|
||||
@@ -47,5 +47,13 @@ std::string percentDecode(const std::string& input) {
|
||||
return decoded;
|
||||
}
|
||||
|
||||
namespace {
|
||||
const std::string assetProtocol = "asset://";
|
||||
}
|
||||
|
||||
bool isAssetURL(const std::string& url) {
|
||||
return std::equal(assetProtocol.begin(), assetProtocol.end(), url.begin());
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace util {
|
||||
std::string percentEncode(const std::string&);
|
||||
std::string percentDecode(const std::string&);
|
||||
|
||||
bool isAssetURL(const std::string&);
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
|
||||
Reference in New Issue
Block a user