Skip to content

Commit

Permalink
Alter all URL sessions to occur through HTTPS even if an HTTP URL is …
Browse files Browse the repository at this point in the history
…passed

Fixed #432
  • Loading branch information
joeljfischer committed Aug 16, 2016
1 parent 11b0b07 commit f0fc5b9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions SmartDeviceLink/SDLURLSession.m
Expand Up @@ -62,6 +62,11 @@ - (instancetype)init {
#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];
Expand All @@ -71,7 +76,13 @@ - (void)dataFromURL:(NSURL *)url completionHandler:(SDLURLConnectionRequestCompl
}

- (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";

Expand Down

0 comments on commit f0fc5b9

Please sign in to comment.