From fe6f7100b88e2e951413a28b5f0ad90acaeb801b Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Tue, 12 Dec 2023 18:04:40 +0100 Subject: [PATCH] workaround to speedup accept matching --- .../server/handlers/ClassRoutingHandler.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java index 1b8fdc9b901d7..8fa974acf8187 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java @@ -170,12 +170,16 @@ private boolean acceptHeaderMatches(RequestMapper.RequestMatch MediaType providedMediaType = producesMediaTypes[0]; return providedMediaType.isCompatible(toMediaType(accepts.trim())); } else if (multipleAcceptsValues && (producesMediaTypes.length == 1)) { - // this is fairly common case, so we want it to be as fast as possible - // we do that by manually splitting the accepts header and immediately checking - // if the value is compatible with the produces media type + // blind fixed-cost attempt for accepts which end up with something like */*;q=0.9 + int acceptLen = accepts.length(); + // indexOf works at its best when the string is long enough + if (acceptLen >= 16) { + if (accepts.indexOf("*/*", acceptLen - 16) != -1) { + return true; + } + } boolean compatible = false; int begin = 0; - do { String acceptPart; if (commaIndex == -1) { // this is the case where we are checking the remainder of the string