Skip to content

Commit

Permalink
workaround to speedup accept matching
Browse files Browse the repository at this point in the history
  • Loading branch information
franz1981 committed Dec 12, 2023
1 parent 2aa086a commit fe6f710
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,16 @@ private boolean acceptHeaderMatches(RequestMapper.RequestMatch<RuntimeResource>
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
Expand Down

0 comments on commit fe6f710

Please sign in to comment.