public static String formatHostnameForHttp(InetSocketAddress addr) {
        String hostString = NetUtil.getHostname(addr);
        if (NetUtil.isValidIpV6Address(hostString)) {
            if (!addr.isUnresolved()) {
                hostString = NetUtil.toAddressString(addr.getAddress());
            } else if (hostString.charAt(0) == '[' && hostString.charAt(hostString.length() - 1) == ']') {
                // If IPv6 address already contains brackets, let's return as is.
                return hostString;
            }

            return '[' + hostString + ']';
        }
        return hostString;
    }
@Test
    public void testIpv4() throws Exception  {
        InetSocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 8080);
        assertEquals("10.0.0.1", HttpUtil.formatHostnameForHttp(socketAddress));
    }