diff --git a/src/main/java/io/github/danthe1st/httpsintercept/config/HostMatcher.java b/src/main/java/io/github/danthe1st/httpsintercept/config/HostMatcher.java deleted file mode 100644 index 90b2edb..0000000 --- a/src/main/java/io/github/danthe1st/httpsintercept/config/HostMatcher.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.danthe1st.httpsintercept.config; - -import java.util.Collections; -import java.util.Set; -import java.util.regex.Pattern; - -public record HostMatcher( - Set exactHosts, - Set hostParts, - Set hostRegexes) { - - public HostMatcher(Set exactHosts, Set hostParts, Set hostRegexes) { - this.exactHosts = copyOrEmptyIfNull(exactHosts); - this.hostParts = copyOrEmptyIfNull(hostParts); - this.hostRegexes = copyOrEmptyIfNull(hostRegexes); - } - - private Set copyOrEmptyIfNull(Set data) { - if(data == null){ - return Collections.emptySet(); - } - return Set.copyOf(data); - } - - public boolean matches(String hostname) { - return exactHosts.contains(hostname) || doesMatchPart(hostname) || matchesRegex(hostname); - } - - private boolean matchesRegex(String hostname) { - for(Pattern pattern : hostRegexes){ - if(pattern.matcher(hostname).matches()){ - return true; - } - } - return false; - } - - private boolean doesMatchPart(String hostname) { - if(hostParts.isEmpty()){ - return false; - } - - int index = 0; - do{ - if(hostParts.contains(hostname.substring(index))){ - return true; - } - }while((index = hostname.indexOf('.', index) + 1) != 0 && index < hostname.length()); - - return false; - } -}