diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java index 83913654db48..abc506830267 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java @@ -79,10 +79,12 @@ private static URI initUri(HttpServerRequest request) throws URISyntaxException return new URI(resolveBaseUrl(request) + resolveRequestUri(request)); } - private static String resolveBaseUrl(HttpServerRequest request) { + private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException { String scheme = request.scheme(); int port = request.hostPort(); - return scheme + "://" + request.hostName() + (usePort(scheme, port) ? ":" + port : ""); + return (usePort(scheme, port) ? + new URI(scheme, null, request.hostName(), port, null, null, null) : + new URI(scheme, request.hostName(), null, null)); } private static boolean usePort(String scheme, int port) {