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 fae7d1ce0494..bcb76e7ab67d 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 @@ -76,17 +76,15 @@ private static URI initUri(HttpServerRequest request) throws URISyntaxException return new URI(resolveBaseUrl(request) + resolveRequestUri(request)); } - private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException { - String scheme = getScheme(request); + private static String resolveBaseUrl(HttpServerRequest request) { + String scheme = request.scheme(); int port = request.hostPort(); - return ((scheme.equals("http") || scheme.equals("ws")) && (port != 80)) || - ((scheme.equals("https") || scheme.equals("wss")) && (port != 443)) ? - new URI(scheme, null, request.hostName(), port, null, null, null) : - new URI(scheme, request.hostName(), null, null); + return scheme + "://" + request.hostName() + (usePort(scheme, port) ? ":" + port : ""); } - private static String getScheme(HttpServerRequest request) { - return request.scheme(); + private static boolean usePort(String scheme, int port) { + return ((scheme.equals("http") || scheme.equals("ws")) && (port != 80)) || + ((scheme.equals("https") || scheme.equals("wss")) && (port != 443)); } private static String resolveRequestUri(HttpServerRequest request) {