diff options
author | Jason Wray <friedbunny@users.noreply.github.com> | 2016-05-13 21:46:13 -0400 |
---|---|---|
committer | Jason Wray <friedbunny@users.noreply.github.com> | 2016-05-13 21:46:13 -0400 |
commit | 0d5d2a923b45c81f3830a60b8e8a45b64827e628 (patch) | |
tree | e1b795ac10ac364e269939c907c51acc6812d855 /platform | |
parent | 1ee14915f8484f22abb59b7ecdb48e197e6dbf38 (diff) | |
download | qtlocation-mapboxgl-0d5d2a923b45c81f3830a60b8e8a45b64827e628.tar.gz |
[ios] Improve telemetry server URL validation (#5022)
- Validate that test server URL actually has a reasonable value.
- Refactor `baseURL` and `testServerURL` to use NSURL.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/ios/src/MGLAPIClient.m | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/platform/ios/src/MGLAPIClient.m b/platform/ios/src/MGLAPIClient.m index 86f57e4e88..2a224c5584 100644 --- a/platform/ios/src/MGLAPIClient.m +++ b/platform/ios/src/MGLAPIClient.m @@ -14,7 +14,7 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST"; @interface MGLAPIClient () @property (nonatomic, copy) NSURLSession *session; -@property (nonatomic, copy) NSString *baseURL; +@property (nonatomic, copy) NSURL *baseURL; @property (nonatomic, copy) NSData *digicertCert; @property (nonatomic, copy) NSData *geoTrustCert; @property (nonatomic, copy) NSData *testServerCert; @@ -76,8 +76,9 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST"; #pragma mark Utilities - (NSURLRequest *)requestForEvents:(NS_ARRAY_OF(MGLMapboxEventAttributes *) *)events { - NSString *url = [NSString stringWithFormat:@"%@/%@?access_token=%@", self.baseURL, MGLAPIClientEventsPath, [MGLAccountManager accessToken]]; - NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; + NSString *path = [NSString stringWithFormat:@"%@?access_token=%@", MGLAPIClientEventsPath, [MGLAccountManager accessToken]]; + NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL]; + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setValue:self.userAgent forHTTPHeaderField:MGLAPIClientHeaderFieldUserAgentKey]; [request setValue:MGLAPIClientHeaderFieldContentTypeValue forHTTPHeaderField:MGLAPIClientHeaderFieldContentTypeKey]; [request setHTTPMethod:MGLAPIClientHTTPMethodPost]; @@ -87,12 +88,13 @@ static NSString * const MGLAPIClientHTTPMethodPost = @"POST"; } - (void)setupBaseURL { - NSString *testServerURL = [[NSUserDefaults standardUserDefaults] stringForKey:@"MGLTelemetryTestServerURL"]; - if (testServerURL) { - _baseURL = testServerURL; - _usesTestServer = YES; + NSString *testServerURLString = [[NSUserDefaults standardUserDefaults] stringForKey:@"MGLTelemetryTestServerURL"]; + NSURL *testServerURL = [NSURL URLWithString:testServerURLString]; + if (testServerURL && [testServerURL.scheme isEqualToString:@"https"]) { + self.baseURL = testServerURL; + self.usesTestServer = YES; } else { - _baseURL = MGLAPIClientBaseURL; + self.baseURL = [NSURL URLWithString:MGLAPIClientBaseURL]; } } |