diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorUriHelper.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorUriHelper.java index ec728485603..223e59a81f6 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorUriHelper.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorUriHelper.java @@ -135,19 +135,22 @@ abstract class ReactorUriHelper { if (c == '/' || c == '?' || c == '#') { break; } - if (c == ':' && (i + 2 < length)) { - if (uri.charAt(i + 1) == '/' && uri.charAt(i + 2) == '/') { - for (int j = i + 3; j < length; j++) { - c = uri.charAt(j); - if (c == '/' || c == '?' || c == '#') { - builder.append(uri, j, length); - return; - } + if (hasAuthority(uri, c, i, length)) { + for (i = i + 3; i < length; i++) { + c = uri.charAt(i); + if (c == '/' || c == '?' || c == '#') { + builder.append(uri, i, length); + return; } - return; } + return; } } builder.append(uri); } + + private static boolean hasAuthority(String uri, char c, int i, int length) { + return (c == ':' && (i + 2 < length) && (uri.charAt(i + 1) == '/' && uri.charAt(i + 2) == '/')); + } + } diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java index 765e185741b..502366dce7d 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java @@ -35,10 +35,11 @@ import static org.mockito.Mockito.mock; */ class ReactorUriHelperTests { + private final HttpServerRequest nettyRequest = mock(); + + @Test void hostnameWithZoneId() throws URISyntaxException { - HttpServerRequest nettyRequest = mock(); - given(nettyRequest.scheme()).willReturn("http"); given(nettyRequest.hostName()).willReturn("fe80::a%en1"); given(nettyRequest.hostPort()).willReturn(80); @@ -50,7 +51,21 @@ class ReactorUriHelperTests { .hasPort(-1) .hasPath("/") .hasToString("http://[fe80::a%25en1]/"); + } + @Test + void requestUriWithScheme() throws URISyntaxException { + given(nettyRequest.scheme()).willReturn("http"); + given(nettyRequest.hostName()).willReturn("example.org"); + given(nettyRequest.hostPort()).willReturn(80); + given(nettyRequest.uri()).willReturn("http://example.org/path"); + + URI uri = ReactorUriHelper.createUri(nettyRequest); + assertThat(uri).hasScheme("http") + .hasHost("example.org") + .hasPort(-1) + .hasPath("/path") + .hasToString("http://example.org/path"); } @ParameterizedTest(name = "{displayName}({arguments})") @@ -61,8 +76,6 @@ class ReactorUriHelperTests { "'' | /", }) void forwardedPrefix(String forwardedPrefixHeader, String expectedPath) throws URISyntaxException { - HttpServerRequest nettyRequest = mock(); - given(nettyRequest.scheme()).willReturn("https"); given(nettyRequest.hostName()).willReturn("localhost"); given(nettyRequest.hostPort()).willReturn(443);