diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2016-08-16 14:47:43 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2016-08-16 14:47:43 -0400 |
commit | f0fc5b9f88fa506eacd7a2e84840f667b5723110 (patch) | |
tree | cfdbf83c5d7fa49582a7f11d4be0fca7d3bd181d | |
parent | 11b0b078aa1ffc1696da0be7036c6bbb7ea4d08b (diff) | |
download | sdl_ios-f0fc5b9f88fa506eacd7a2e84840f667b5723110.tar.gz |
Alter all URL sessions to occur through HTTPS even if an HTTP URL is passed
Fixed #432
-rw-r--r-- | SmartDeviceLink/SDLURLSession.m | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/SmartDeviceLink/SDLURLSession.m b/SmartDeviceLink/SDLURLSession.m index 363c6fbad..f0ed1842c 100644 --- a/SmartDeviceLink/SDLURLSession.m +++ b/SmartDeviceLink/SDLURLSession.m @@ -62,6 +62,11 @@ static float DefaultConnectionTimeout = 45.0; #pragma mark - URL Request Methods - (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"]]; + } + NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:self.cachePolicy timeoutInterval:self.connectionTimeout]; SDLURLRequestTask *task = [[SDLURLRequestTask alloc] initWithURLRequest:request completionHandler:completionHandler]; @@ -71,7 +76,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"]]; + } + NSMutableURLRequest *mutableRequest = [request mutableCopy]; + mutableRequest.URL = newURL; mutableRequest.HTTPBody = data; mutableRequest.HTTPMethod = @"POST"; |