diff --git a/Limelight/Network/HttpManager.m b/Limelight/Network/HttpManager.m index 6bef638b..181fac07 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; }