diff --git a/build.gradle b/build.gradle index 2a6e1e28ef8..c30e5f47b32 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ configure(allprojects) { project -> imports { mavenBom "com.fasterxml.jackson:jackson-bom:2.12.7" mavenBom "io.netty:netty-bom:4.1.89.Final" - mavenBom "io.projectreactor:reactor-bom:2020.0.27" + mavenBom "io.projectreactor:reactor-bom:2020.0.29" mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR13" mavenBom "io.rsocket:rsocket-bom:1.1.3" mavenBom "org.eclipse.jetty:jetty-bom:9.4.51.v20230217" 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 4e341ee3bfc..83913654db4 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 @@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicLong; import javax.net.ssl.SSLSession; import io.netty.channel.Channel; -import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.ssl.SslHandler; import org.apache.commons.logging.Log; @@ -80,42 +79,15 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { return new URI(resolveBaseUrl(request) + resolveRequestUri(request)); } - private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException { - String scheme = getScheme(request); - - InetSocketAddress hostAddress = request.hostAddress(); - if (hostAddress != null) { - return new URI(scheme, null, hostAddress.getHostString(), hostAddress.getPort(), null, null, null); - } - - String header = request.requestHeaders().get(HttpHeaderNames.HOST); - if (header != null) { - final int portIndex; - if (header.startsWith("[")) { - portIndex = header.indexOf(':', header.indexOf(']')); - } - else { - portIndex = header.indexOf(':'); - } - if (portIndex != -1) { - try { - return new URI(scheme, null, header.substring(0, portIndex), - Integer.parseInt(header.substring(portIndex + 1)), null, null, null); - } - catch (NumberFormatException ex) { - throw new URISyntaxException(header, "Unable to parse port", portIndex); - } - } - else { - return new URI(scheme, header, null, null); - } - } - - throw new IllegalStateException("Neither local hostAddress nor HOST header available"); + private static String resolveBaseUrl(HttpServerRequest request) { + String scheme = request.scheme(); + int port = request.hostPort(); + 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) {