summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2016-08-18 09:16:58 -0400
committerJoel Fischer <joeljfischer@gmail.com>2016-08-18 09:16:58 -0400
commit0d3dce6a2e1a4e17630a3ad7532f713917b6c943 (patch)
tree6e36d46946309e0b8b45786131237aec395a68fa
parent3b89c1915cd60a801c81685044dc1560b01ab967 (diff)
downloadsdl_ios-0d3dce6a2e1a4e17630a3ad7532f713917b6c943.tar.gz
Change HTTP alerting in SDLURLSession to use NSURLComponents
Fixes #432
-rw-r--r--SmartDeviceLink/SDLURLSession.m15
1 files changed, 8 insertions, 7 deletions
diff --git a/SmartDeviceLink/SDLURLSession.m b/SmartDeviceLink/SDLURLSession.m
index 3e2ad6e1c..5e70a7bc1 100644
--- a/SmartDeviceLink/SDLURLSession.m
+++ b/SmartDeviceLink/SDLURLSession.m
@@ -63,11 +63,12 @@ static float DefaultConnectionTimeout = 45.0;
- (void)dataFromURL:(NSURL *)url completionHandler:(SDLURLConnectionRequestCompletionHandler)completionHandler {
// Apple no longer allows HTTP URLs without a special exception as of Jan. 2017
- if ([url.scheme isEqualToString:@"http"]) {
- url = [NSURL URLWithString:[url.absoluteString stringByReplacingOccurrencesOfString:@"http" withString:@"https"]];
+ NSURLComponents *urlComponents = [NSURLComponents componentsWithString:url.absoluteString];
+ if ([urlComponents.scheme isEqualToString:@"http"]) {
+ urlComponents.scheme = @"https";
}
- NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:self.cachePolicy timeoutInterval:self.connectionTimeout];
+ NSURLRequest *request = [NSURLRequest requestWithURL:urlComponents.URL cachePolicy:self.cachePolicy timeoutInterval:self.connectionTimeout];
SDLURLRequestTask *task = [[SDLURLRequestTask alloc] initWithURLRequest:request completionHandler:completionHandler];
task.delegate = self;
@@ -76,13 +77,13 @@ static float DefaultConnectionTimeout = 45.0;
}
- (void)uploadWithURLRequest:(NSURLRequest *)request data:(NSData *)data completionHandler:(SDLURLConnectionRequestCompletionHandler)completionHandler {
- NSURL *newURL = nil;
- if ([request.URL.scheme isEqualToString:@"http"]) {
- newURL = [NSURL URLWithString:[request.URL.absoluteString stringByReplacingOccurrencesOfString:@"http" withString:@"https"]];
+ NSURLComponents *urlComponents = [NSURLComponents componentsWithString:request.URL.absoluteString];
+ if ([urlComponents.scheme isEqualToString:@"http"]) {
+ urlComponents.scheme = @"https";
}
NSMutableURLRequest *mutableRequest = [request mutableCopy];
- mutableRequest.URL = newURL;
+ mutableRequest.URL = urlComponents.URL;
mutableRequest.HTTPBody = data;
mutableRequest.HTTPMethod = @"POST";