summaryrefslogtreecommitdiff
path: root/platform/darwin/src/http_file_source.mm
diff options
context:
space:
mode:
Diffstat (limited to 'platform/darwin/src/http_file_source.mm')
-rw-r--r--platform/darwin/src/http_file_source.mm43
1 files changed, 32 insertions, 11 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm
index 0d14c44c01..79810546b3 100644
--- a/platform/darwin/src/http_file_source.mm
+++ b/platform/darwin/src/http_file_source.mm
@@ -196,24 +196,45 @@ HTTPFileSource::HTTPFileSource()
HTTPFileSource::~HTTPFileSource() = default;
+MGL_EXPORT
+NSURL *resourceURLWithAccountType(const Resource& resource, NSInteger accountType) {
+
+ NSURL *url = [NSURL URLWithString:@(resource.url.c_str())];
+
+#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
+ if (accountType == 0 &&
+ ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"])) {
+ NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
+ NSURLQueryItem *accountsQueryItem = [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken];
+
+ NSMutableArray *queryItems = [NSMutableArray arrayWithObject:accountsQueryItem];
+
+ // offline here
+ if (resource.usage == Resource::Usage::Offline) {
+ [queryItems addObject:[NSURLQueryItem queryItemWithName:@"offline" value:@"true"]];
+ }
+
+ if (components.queryItems) {
+ [queryItems addObjectsFromArray:components.queryItems];
+ }
+
+ components.queryItems = queryItems;
+ url = components.URL;
+ }
+#else
+ (void)accountType;
+#endif
+ return url;
+}
+
std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, Callback callback) {
auto request = std::make_unique<HTTPRequest>(callback);
auto shared = request->shared; // Explicit copy so that it also gets copied into the completion handler block below.
@autoreleasepool {
- NSURL *url = [NSURL URLWithString:@(resource.url.c_str())];
+ NSURL *url = resourceURLWithAccountType(resource, impl->accountType);
MGLLogDebug(@"Requesting URI: %@", url.relativePath);
-#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
- if (impl->accountType == 0 &&
- ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"])) {
- NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
- NSURLQueryItem *accountsQueryItem = [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken];
- components.queryItems = components.queryItems ? [components.queryItems arrayByAddingObject:accountsQueryItem] : @[accountsQueryItem];
- url = components.URL;
- }
-#endif
-
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
if (resource.priorEtag) {
[req addValue:@(resource.priorEtag->c_str())