From 94bc3c811fa3ad08a03800a180916c9560cbfd60 Mon Sep 17 00:00:00 2001 From: Brad Leege Date: Thu, 2 Apr 2015 16:15:25 -0500 Subject: [PATCH] #1185 - Adding "events=true" query string to all non metrics http requests if metrics are not disabled --- platform/darwin/http_request_nsurl.mm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm index 638b5062d..7be5f226f 100644 --- a/platform/darwin/http_request_nsurl.mm +++ b/platform/darwin/http_request_nsurl.mm @@ -141,8 +141,19 @@ void HTTPRequestImpl::start() { attempts++; @autoreleasepool { + + NSMutableString *url = [[NSMutableString alloc] initWithString:@(request->resource.url.c_str())]; + if ([[NSUserDefaults standardUserDefaults] objectForKey:@"mapbox_metrics_disabled"] == nil) { + if ([url rangeOfString:@"?"].location == NSNotFound) { + [url appendString:@"?"]; + } else { + [url appendString:@"&"]; + } + [url appendString:@"events=true"]; + } + NSMutableURLRequest *req = [[NSMutableURLRequest alloc] - initWithURL:[NSURL URLWithString:@(request->resource.url.c_str())]]; + initWithURL:[NSURL URLWithString:url]]; if (existingResponse) { if (!existingResponse->etag.empty()) { [req addValue:@(existingResponse->etag.c_str()) forHTTPHeaderField:@"If-None-Match"];