in httpclient5/src/main/java/org/apache/hc/client5/http/psl/PublicSuffixMatcher.java [134:181]
public String getDomainRoot(final String domain, final DomainType expectedType) {
if (domain == null) {
return null;
}
if (domain.startsWith(".")) {
return null;
}
String segment = DnsUtils.normalize(domain);
String result = null;
while (segment != null) {
// An exception rule takes priority over any other matching rule.
final String key = IDN.toUnicode(segment);
final DomainType exceptionRule = findEntry(exceptions, key);
if (match(exceptionRule, expectedType)) {
return segment;
}
final DomainType domainRule = findEntry(rules, key);
if (match(domainRule, expectedType)) {
if (domainRule == DomainType.PRIVATE) {
return segment;
}
return result;
}
final int nextdot = segment.indexOf('.');
final String nextSegment = nextdot != -1 ? segment.substring(nextdot + 1) : null;
if (nextSegment != null) {
final DomainType wildcardDomainRule = findEntry(rules, "*." + IDN.toUnicode(nextSegment));
if (match(wildcardDomainRule, expectedType)) {
if (wildcardDomainRule == DomainType.PRIVATE) {
return segment;
}
return result;
}
}
result = segment;
segment = nextSegment;
}
// If no expectations then this result is good.
if (expectedType == null || expectedType == DomainType.UNKNOWN) {
return result;
}
// If we did have expectations apparently there was no match
return null;
}