in spectator-ext-ipc/src/main/java/com/netflix/spectator/ipc/http/HostSanitizer.java [126:153]
private static String sanitizeSegments(String host, Set<String> allowed) {
HostStringBuilder builder = new HostStringBuilder();
int last = host.length();
int pos = host.lastIndexOf('.');
while (pos >= 0) {
String segment = host.substring(pos + 1, last);
last = pos;
pos = host.lastIndexOf('.', last - 1);
if (!segment.isEmpty()) {
if (shouldSuppressSegment(segment, allowed))
segment = "_";
if (!builder.prepend(segment))
break;
}
}
if (pos == -1) {
String segment = host.substring(0, last);
if (!segment.isEmpty()) {
if (shouldSuppressSegment(segment, allowed))
segment = "_";
builder.prepend(segment);
}
}
return builder.toString();
}