public static String sanitizeDefaultPort(String url) {
        int afterSchemeIndex = url.indexOf("://");
        if(afterSchemeIndex < 0) {
            return url;
        }
        String scheme = url.substring(0, afterSchemeIndex);
        int fromIndex = scheme.length() + 3;
        //Let's see if it is an IPv6 Address
        int ipv6StartIndex = url.indexOf('[', fromIndex);
        if (ipv6StartIndex > 0) {
            fromIndex = url.indexOf(']', ipv6StartIndex);
        }
        int portIndex = url.indexOf(':', fromIndex);
        if(portIndex >= 0) {
            int port = Integer.parseInt(url.substring(portIndex + 1));
            if(isDefaultPort(port, scheme)) {
                return url.substring(0, portIndex);
            }
        }
        return url;
    }
@Test
    public void testSanitizeDefaultPort() {
        String url = "http://127.0.0.1:80";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("http://127.0.0.1"));
        url = "http://127.0.0.1";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("http://127.0.0.1"));
        url = "http://127.0.0.1:443";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("http://127.0.0.1:443"));
        url = "http://127.0.0.1:7080";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("http://127.0.0.1:7080"));
        url = "https://127.0.0.1:80";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("https://127.0.0.1:80"));
        url = "https://127.0.0.1:443";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("https://127.0.0.1"));
        url = "https://127.0.0.1";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("https://127.0.0.1"));
        url = "http://[::FFFF:129.144.52.38]:7080";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("http://[::FFFF:129.144.52.38]:7080"));
        url = "http://[::FFFF:129.144.52.38]:80";
        assertThat(CorsUtil.sanitizeDefaultPort(url), is("http://[::FFFF:129.144.52.38]"));
    }