diff options
author | Jason Wray <friedbunny@users.noreply.github.com> | 2019-04-17 18:27:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-17 18:27:54 -0700 |
commit | d5569f4b01ea82ebb9221ef9ed9df71ba8ba5dd9 (patch) | |
tree | a0d3b6b471b0309ce149ba14d998ae035233e45c /platform/darwin/src/http_file_source.mm | |
parent | b3b62f4d5abd5bc779e564cc71e5adf0ccc924cc (diff) | |
download | qtlocation-mapboxgl-d5569f4b01ea82ebb9221ef9ed9df71ba8ba5dd9.tar.gz |
[ios] Add SKU tokens to all Mapbox requests (#14421)
Diffstat (limited to 'platform/darwin/src/http_file_source.mm')
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index c26568d8bc..29f8f7db68 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -7,9 +7,14 @@ #include <mbgl/util/version.hpp> #import <Foundation/Foundation.h> + #import "MGLLoggingConfiguration_Private.h" #import "MGLNetworkConfiguration_Private.h" +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR +#import "MGLAccountManager_Private.h" +#endif + #include <mutex> #include <chrono> @@ -196,16 +201,25 @@ std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, 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 = [NSURL URLWithString:@(resource.url.c_str())]; 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"])) { - NSString* absoluteString = [url.absoluteString - stringByAppendingFormat:(url.query ? @"&%@" : @"?%@"), @"events=true"]; - url = [NSURL URLWithString:absoluteString]; + NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; + NSArray *newQueryItems = @[ + [NSURLQueryItem queryItemWithName:@"events" value:@"true"], + [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken] + ]; + + components.queryItems = components.queryItems ? [components.queryItems arrayByAddingObjectsFromArray:newQueryItems] : newQueryItems; + + url = components.URL; } +#endif - NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:url]; + NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; if (resource.priorEtag) { [req addValue:@(resource.priorEtag->c_str()) forHTTPHeaderField:@"If-None-Match"]; |