From 0c736dfd2905f3b28378a18aad213ff6865afc3c Mon Sep 17 00:00:00 2001 From: Bala FA Date: Fri, 13 May 2022 19:51:15 +0530 Subject: [PATCH] fix Host header value for IPv6 (#1328) Signed-off-by: Bala.FA --- api/src/main/java/io/minio/http/HttpUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/io/minio/http/HttpUtils.java b/api/src/main/java/io/minio/http/HttpUtils.java index ab6a4dc31..3a2672831 100644 --- a/api/src/main/java/io/minio/http/HttpUtils.java +++ b/api/src/main/java/io/minio/http/HttpUtils.java @@ -112,13 +112,18 @@ public static HttpUrl getBaseUrl(String endpoint) { } public static String getHostHeader(HttpUrl url) { + String host = url.host(); + if (InetAddressValidator.getInstance().isValidInet6Address(host)) { + host = "[" + host + "]"; + } + // ignore port when port and service matches i.e HTTP -> 80, HTTPS -> 443 if ((url.scheme().equals("http") && url.port() == 80) || (url.scheme().equals("https") && url.port() == 443)) { - return url.host(); + return host; } - return url.host() + ":" + url.port(); + return host + ":" + url.port(); } /**