diff --git a/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m b/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m index a111a6d62..a22f3a078 100644 --- a/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m +++ b/SocketRocket/Internal/Utilities/SRHTTPConnectMessage.m @@ -17,7 +17,11 @@ { NSString *host = url.host; if (url.port) { - host = [host stringByAppendingFormat:@":%@", url.port]; + if ([host containsString:@":"]) { + host = [NSString stringWithFormat:@"[%@]:%@", host, url.port]; + } else { + host = [host stringByAppendingFormat:@":%@", url.port]; + } } return host; } diff --git a/SocketRocket/Internal/Utilities/SRURLUtilities.m b/SocketRocket/Internal/Utilities/SRURLUtilities.m index fbb942961..1d7e45378 100644 --- a/SocketRocket/Internal/Utilities/SRURLUtilities.m +++ b/SocketRocket/Internal/Utilities/SRURLUtilities.m @@ -23,7 +23,13 @@ } else if ([scheme isEqualToString:@"ws"]) { scheme = @"http"; } - [origin appendFormat:@"%@://%@", scheme, url.host]; + + NSString * host = url.host; + if ([host containsString:@":"]) { + host = [NSString stringWithFormat:@"[%@]", host]; + } + + [origin appendFormat:@"%@://%@", scheme, host]; NSNumber *port = url.port; BOOL portIsDefault = (!port ||