diff --git a/src/main/java/org/littleshoot/proxy/HttpRequestHandler.java b/src/main/java/org/littleshoot/proxy/HttpRequestHandler.java index 864b7f0..7563207 100644 --- a/src/main/java/org/littleshoot/proxy/HttpRequestHandler.java +++ b/src/main/java/org/littleshoot/proxy/HttpRequestHandler.java @@ -443,15 +443,30 @@ public class HttpRequestHandler extends SimpleChannelUpstreamHandler final Channel browserToProxyChannel) { final String host; final int port; - if (hostAndPort.contains(":")) { - host = StringUtils.substringBefore(hostAndPort, ":"); - final String portString = - StringUtils.substringAfter(hostAndPort, ":"); - port = Integer.parseInt(portString); - } - else { - host = hostAndPort; - port = 80; + if (hostAndPort.contains("[") && hostAndPort.contains("]")) { + int idx = hostAndPort.lastIndexOf("]"); + int cIdx = hostAndPort.lastIndexOf(":"); + if (cIdx > idx) { + host = hostAndPort.substring(0, idx + 1); + final String portString = + hostAndPort.substring(cIdx + 1); + port = Integer.parseInt(portString); + } + else { + host = hostAndPort; + port = 80; + } + } else { + if (hostAndPort.contains(":")) { + host = StringUtils.substringBefore(hostAndPort, ":"); + final String portString = + StringUtils.substringAfter(hostAndPort, ":"); + port = Integer.parseInt(portString); + } + else { + host = hostAndPort; + port = 80; + } } // Configure the client.