Polishing in ReactorUriHelper

See gh-36893
This commit is contained in:
rstoyanchev
2026-06-22 11:06:43 +01:00
parent 76089feeb4
commit 0e4842062b
2 changed files with 29 additions and 13 deletions
@@ -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) == '/'));
}
}
@@ -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);