From 90b70180c53c2945c10b9520f9e6aa5f4f697ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 19 May 2015 13:44:29 -0700 Subject: [PATCH 1/3] Compare hostname for adding events=true ref #1596, #1599 --- platform/darwin/http_request_nsurl.mm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index 85d5bffb0..bdae9ce51 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -153,19 +153,16 @@ void HTTPRequest::start() { @autoreleasepool { - NSMutableString *url = [NSMutableString stringWithString:@(resource.url.c_str())]; - if ([url rangeOfString:@"mapbox.com"].location != NSNotFound) { + NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; + if ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"]) { if ([[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0) { - if ([url rangeOfString:@"?"].location == NSNotFound) { - [url appendString:@"?"]; - } else { - [url appendString:@"&"]; - } - [url appendString:@"events=true"]; + NSString *absoluteString = [url.absoluteString stringByAppendingFormat: + (url.query ? @"&%@" : @"?%@"), @"events=true"]; + url = [NSURL URLWithString:absoluteString]; } } - NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; + NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; if (existingResponse) { if (!existingResponse->etag.empty()) { [req addValue:@(existingResponse->etag.c_str()) forHTTPHeaderField:@"If-None-Match"]; From 52670f05601e35804e79f1ee197f2042a9c94a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 19 May 2015 14:31:30 -0700 Subject: [PATCH 2/3] Cache account type user default --- platform/darwin/http_request_nsurl.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index bdae9ce51..ef88469b4 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -91,6 +91,7 @@ public: NSURLSession *session = nil; NSString *userAgent = nil; + NSInteger accountType = 0; }; HTTPNSURLContext::HTTPNSURLContext(uv_loop_t *loop_) : HTTPContext(loop_) { @@ -107,6 +108,8 @@ HTTPNSURLContext::HTTPNSURLContext(uv_loop_t *loop_) : HTTPContext(loop_) { // Write user agent string userAgent = @"MapboxGL"; + + accountType = [[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"]; } } @@ -155,7 +158,7 @@ void HTTPRequest::start() { NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; if ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"]) { - if ([[NSUserDefaults standardUserDefaults] integerForKey:@"MGLMapboxAccountType"] == 0) { + if (context->accountType == 0) { NSString *absoluteString = [url.absoluteString stringByAppendingFormat: (url.query ? @"&%@" : @"?%@"), @"events=true"]; url = [NSURL URLWithString:absoluteString]; From d474f35371b12d95e2a732d61d1d9f1d9a3f322c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 19 May 2015 14:33:19 -0700 Subject: [PATCH 3/3] Check account type before comparing hostname --- platform/darwin/http_request_nsurl.mm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index ef88469b4..ad16a69ac 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -157,12 +157,11 @@ void HTTPRequest::start() { @autoreleasepool { NSURL *url = [NSURL URLWithString:@(resource.url.c_str())]; - if ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"]) { - if (context->accountType == 0) { - NSString *absoluteString = [url.absoluteString stringByAppendingFormat: - (url.query ? @"&%@" : @"?%@"), @"events=true"]; - url = [NSURL URLWithString:absoluteString]; - } + if (context->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]; } NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];