From b9d5d94d708173c928e555c2e82afa60e871b304 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 20 Jan 2018 01:30:29 -0800 Subject: [PATCH] Fix support for IPv6 literals --- Limelight/Network/HttpManager.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Limelight/Network/HttpManager.m b/Limelight/Network/HttpManager.m index 6bef638..181fac0 100644 --- a/Limelight/Network/HttpManager.m +++ b/Limelight/Network/HttpManager.m @@ -18,7 +18,6 @@ NSURLSession* _urlSession; NSString* _baseHTTPURL; NSString* _baseHTTPSURL; - NSString* _host; NSString* _uniqueId; NSString* _deviceName; NSData* _cert; @@ -41,16 +40,25 @@ static const NSString* HTTPS_PORT = @"47984"; - (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName cert:(NSData*) cert { self = [super init]; - _host = host; _uniqueId = uniqueId; _deviceName = deviceName; _cert = cert; - _baseHTTPURL = [NSString stringWithFormat:@"http://%@:%@", host, HTTP_PORT]; - _baseHTTPSURL = [NSString stringWithFormat:@"https://%@:%@", host, HTTPS_PORT]; _requestLock = dispatch_semaphore_create(0); _respData = [[NSMutableData alloc] init]; NSURLSessionConfiguration* config = [NSURLSessionConfiguration ephemeralSessionConfiguration]; _urlSession = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil]; + + // If this is an IPv6 literal, we must properly enclose it in brackets + NSString* urlSafeHost; + if ([host containsString:@":"]) { + urlSafeHost = [NSString stringWithFormat:@"[%@]", host]; + } else { + urlSafeHost = host; + } + + _baseHTTPURL = [NSString stringWithFormat:@"http://%@:%@", urlSafeHost, HTTP_PORT]; + _baseHTTPSURL = [NSString stringWithFormat:@"https://%@:%@", urlSafeHost, HTTPS_PORT]; + return self; }