package org.xbib.net.scheme;

import org.xbib.net.PathNormalizer;
import org.xbib.net.URL;

import java.util.Locale;

/**
 * HTTPS scheme.
 */
public class HttpsScheme extends AbstractScheme {

    public HttpsScheme() {
        super("https", 443);
    }

    public HttpsScheme(String name, int port) {
        super(name, port);
    }

    @Override
    public URL normalize(URL url) {
        String host = url.getHost();
        if (host != null) {
            host = host.toLowerCase(Locale.ROOT);
        }
        return URL.builder()
                .scheme(url.getScheme())
                .userInfo(url.getUserInfo())
                .host(host, url.getProtocolVersion())
                .port(url.getPort())
                .path(PathNormalizer.normalize(url.getPath()))
                .query(url.getQuery())
                .fragment(url.getFragment())
                .build();
    }
}
