fix: return url without port if default port protocol is used (#1511)

* fix: return url without port if default port protocol is used

* tests: set server port to 8080 and assert that all generated url use port 8080
This commit is contained in:
Florian BEZANNIER
2024-01-31 08:34:07 +01:00
committed by GitHub
parent 537a942021
commit a5dda8cb47
5 changed files with 61 additions and 11 deletions

View File

@@ -102,7 +102,7 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
String urlPattern = protocol.getRef();
for (final Entry<String, String> entry : entrySet) {
if (entry.getKey().equals(PORT_PLACEHOLDER)) {
if (List.of(PORT_PLACEHOLDER,PORT_REQUEST_PLACEHOLDER).contains(entry.getKey())) {
urlPattern = urlPattern.replace(":{" + entry.getKey() + "}",
ObjectUtils.isEmpty(entry.getValue()) ? "" : (":" + entry.getValue()));
} else {
@@ -157,8 +157,8 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
if (requestUri == null) {
return getPort(protocol);
}
return requestUri.getPort() > 0 ? String.valueOf(requestUri.getPort()) : getPort(protocol);
// if port undefined then default protocol port is used
return requestUri.getPort() > 0 ? String.valueOf(requestUri.getPort()) : "";
}
private static String getRequestHost(final UrlProtocol protocol, final URI requestUri) {