Skip to content

Commit cdddc5d

Browse files
shawkinsgeoand
authored andcommitted
fix: adding scheme and authority to absoluteUri
closes: quarkusio#47785 Signed-off-by: Steve Hawkins <[email protected]>
1 parent 8b505d6 commit cdddc5d

File tree

2 files changed

+70
-5
lines changed

2 files changed

+70
-5
lines changed

independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/ResteasyReactiveRequestContext.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,13 @@ public String getPath() {
462462

463463
public String getAbsoluteURI() {
464464
// if we never changed the path we can use the vert.x URI
465-
if (path == null)
465+
if (path == null) {
466466
return serverRequest().getRequestAbsoluteUri();
467+
}
467468
// Note: we could store our cache as normalised, but I'm not sure if the vertx one is normalised
468469
if (absoluteUri == null) {
469470
try {
470-
absoluteUri = new URI(scheme, authority, path, null, null).toASCIIString();
471+
absoluteUri = new URI(getScheme(), getAuthority(), path, null, null).toASCIIString();
471472
} catch (URISyntaxException e) {
472473
throw new RuntimeException(e);
473474
}
@@ -476,14 +477,16 @@ public String getAbsoluteURI() {
476477
}
477478

478479
public String getScheme() {
479-
if (scheme == null)
480+
if (scheme == null) {
480481
return serverRequest().getRequestScheme();
482+
}
481483
return scheme;
482484
}
483485

484486
public String getAuthority() {
485-
if (authority == null)
487+
if (authority == null) {
486488
return serverRequest().getRequestHost();
489+
}
487490
return authority;
488491
}
489492

@@ -1012,7 +1015,7 @@ public void onComplete(Throwable throwable) {
10121015
select.destroy(instance);
10131016
}
10141017
});
1015-
return (T) instance;
1018+
return instance;
10161019
}
10171020
}
10181021
throw new IllegalStateException("Unsupported bean param type: " + type);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.jboss.resteasy.reactive.server;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.net.URI;
6+
import java.util.concurrent.Executor;
7+
8+
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
9+
import org.jboss.resteasy.reactive.server.spi.ServerHttpRequest;
10+
import org.jboss.resteasy.reactive.server.spi.ServerHttpResponse;
11+
import org.junit.jupiter.api.Test;
12+
import org.mockito.Mockito;
13+
14+
public class ResteasyReactiveRequestContextTest {
15+
16+
@Test
17+
void testAbsoluteUriWithOverrides() {
18+
var request = Mockito.mock(ServerHttpRequest.class);
19+
var context = new ResteasyReactiveRequestContext(null, null, null, null) {
20+
21+
@Override
22+
public ServerHttpResponse serverResponse() {
23+
return null;
24+
}
25+
26+
@Override
27+
public ServerHttpRequest serverRequest() {
28+
return request;
29+
}
30+
31+
@Override
32+
public boolean resumeExternalProcessing() {
33+
return false;
34+
}
35+
36+
@Override
37+
public Runnable registerTimer(long millis, Runnable task) {
38+
return null;
39+
}
40+
41+
@Override
42+
protected Executor getEventLoop() {
43+
return null;
44+
}
45+
46+
@Override
47+
protected void setQueryParamsFrom(String uri) {
48+
49+
}
50+
};
51+
Mockito.when(request.getRequestNormalisedPath()).thenReturn("/path;a");
52+
Mockito.when(request.getRequestScheme()).thenReturn("http");
53+
Mockito.when(request.getRequestHost()).thenReturn("host:port");
54+
55+
context.initPathSegments();
56+
assertEquals("http://host:port/path", context.getAbsoluteURI());
57+
58+
context.setRequestUri(URI.create("https://host1:port1/path1"));
59+
assertEquals("https://host1:port1/path1", context.getAbsoluteURI());
60+
}
61+
62+
}

0 commit comments

Comments
 (0)