Ignore quality factor when filtering out "*/*"
Prior to this commit, the `RequestedContentTypeResolverBuilder` would create a `RequestedContentTypeResolver` that internally delegates to a list of resolvers. Each resolver would either return the list of requested media types, or a singleton list with the "*/*" media type; in this case this signals that the resolver cannot find a specific media type requested and that we should continue with the next resolver in the list. Media Types returned by resolvers can contain parameters, such as the quality factor. If the HTTP client requests "*/*;q=0.8", the `HeaderContentTypeResolver` will return this as a singleton list. While this has been resolved from the request, such a media type should not be selected over other media types that could be returned by other resolvers. This commit changes the `RequestedContentTypeResolverBuilder` so that it does not select "*/*;q=0.8" as the requested media type, but instead continues delegating to other resolvers in the list. This means we need to remove the quality factor before comparing it to the "*/*" for equality check. Fixes gh-29915
This commit is contained in:
@@ -93,7 +93,7 @@ public class RequestedContentTypeResolverBuilder {
|
||||
return exchange -> {
|
||||
for (RequestedContentTypeResolver resolver : resolvers) {
|
||||
List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange);
|
||||
if (mediaTypes.equals(RequestedContentTypeResolver.MEDIA_TYPE_ALL_LIST)) {
|
||||
if (isMediaTypeAll(mediaTypes)) {
|
||||
continue;
|
||||
}
|
||||
return mediaTypes;
|
||||
@@ -102,6 +102,11 @@ public class RequestedContentTypeResolverBuilder {
|
||||
};
|
||||
}
|
||||
|
||||
private boolean isMediaTypeAll(List<MediaType> mediaTypes) {
|
||||
return mediaTypes.size() == 1
|
||||
&& mediaTypes.get(0).removeQualityValue().equals(MediaType.ALL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper to create and configure {@link ParameterContentTypeResolver}.
|
||||
|
||||
Reference in New Issue
Block a user