mirror of
https://github.com/floci-io/floci.git
synced 2026-12-04 10:38:00 -05:00
perf(core): build the query parameter map only for a request with a query string (#7978)
* perf(core): build the query parameter map only for a request with a query string RESTEasy builds the query parameter map on the first read and wraps it in a new map on every read. The protocol claim, the account filter, the signing service lookup and the Query protocol entry point read it on every request of every service, even when the request has no query string. Such a request now gets a shared empty map. * perf(core): read the Query protocol query string only without an Authorization header The injected request context in the Query POST entry point is a CDI proxy, so the shared helper could not see the server request and built the map anyway. The query is only needed when the Authorization header is absent.
This commit is contained in:
1 parent
bfea1bec1c
commit
ba28970a94
7 files changed
+111
-14
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package io.floci.aws.core.common;
|
||||
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
|
||||
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveContainerRequestContext;
|
||||
import org.jboss.resteasy.reactive.server.spi.ServerHttpRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class ResteasyRequestsTest {
|
||||
|
||||
private static MultivaluedMap<String, String> uriInfoMap(ContainerRequestContext ctx) {
|
||||
MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
|
||||
map.add("a", "b");
|
||||
UriInfo uriInfo = mock(UriInfo.class);
|
||||
when(uriInfo.getQueryParameters()).thenReturn(map);
|
||||
when(ctx.getUriInfo()).thenReturn(uriInfo);
|
||||
return map;
|
||||
}
|
||||
|
||||
private static ResteasyReactiveContainerRequestContext reactiveContext(String query) {
|
||||
ResteasyReactiveContainerRequestContext ctx = mock(ResteasyReactiveContainerRequestContext.class);
|
||||
ResteasyReactiveRequestContext request = mock(ResteasyReactiveRequestContext.class);
|
||||
ServerHttpRequest serverRequest = mock(ServerHttpRequest.class);
|
||||
when(serverRequest.query()).thenReturn(query);
|
||||
when(request.serverRequest()).thenReturn(serverRequest);
|
||||
when(ctx.getServerRequestContext()).thenReturn(request);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Test
|
||||
void syntheticContextReadsUriInfo() {
|
||||
ContainerRequestContext ctx = mock(ContainerRequestContext.class);
|
||||
MultivaluedMap<String, String> map = uriInfoMap(ctx);
|
||||
|
||||
assertSame(map, ResteasyRequests.queryParameters(ctx));
|
||||
assertNull(ResteasyRequests.of(ctx));
|
||||
}
|
||||
|
||||
@Test
|
||||
void noQueryStringSkipsTheMap() {
|
||||
ResteasyReactiveContainerRequestContext ctx = reactiveContext(null);
|
||||
|
||||
assertTrue(ResteasyRequests.queryParameters(ctx).isEmpty());
|
||||
verify(ctx, never()).getUriInfo();
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryStringReadsUriInfo() {
|
||||
ResteasyReactiveContainerRequestContext ctx = reactiveContext("a=b");
|
||||
MultivaluedMap<String, String> map = uriInfoMap(ctx);
|
||||
|
||||
assertSame(map, ResteasyRequests.queryParameters(ctx));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user