in httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java [1114:1165]
public URIBuilder optimize() {
final String scheme = this.scheme;
if (scheme != null) {
this.scheme = TextUtils.toLowerCase(scheme);
}
if (this.pathRootless) {
return this;
}
// Force Percent-Encoding re-encoding
this.encodedSchemeSpecificPart = null;
this.encodedAuthority = null;
this.encodedUserInfo = null;
this.encodedPath = null;
this.encodedQuery = null;
this.encodedFragment = null;
final String host = this.host;
if (host != null) {
this.host = TextUtils.toLowerCase(host);
}
if (this.pathSegments != null) {
final List<String> inputSegments = this.pathSegments;
if (!inputSegments.isEmpty()) {
final LinkedList<String> outputSegments = new LinkedList<>();
for (final String inputSegment : inputSegments) {
if (!inputSegment.isEmpty() && !".".equals(inputSegment)) {
if ("..".equals(inputSegment)) {
if (!outputSegments.isEmpty()) {
outputSegments.removeLast();
}
} else {
outputSegments.addLast(inputSegment);
}
}
}
if (!inputSegments.isEmpty()) {
final String lastSegment = inputSegments.get(inputSegments.size() - 1);
if (lastSegment.isEmpty()) {
outputSegments.addLast("");
}
}
this.pathSegments = outputSegments;
} else {
this.pathSegments = Collections.singletonList("");
}
}
return this;
}