-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Describe the bug
httpHeaders.getAcceptableMediaTypes() in the end calls MediaTypeHelper.sortByWeight which ignores the third rule if all other rules are equal:
- Quality values (q) are checked first. WORKS
- If there's a tie, the most specific range wins (e.g., text/html wins over text/*). WORKS
- If there's still a tie, the order of appearance in the header is used. IS MISSING
E.g the following header "application/json,text/html; charset=UTF-8,text/plain; charset=UTF-8,/;q=0.8" should return "application/json" as first element of the list since the three types have the same quality and specifity.
The problem in the code is that the sort is done with a "simple" MediaTypeComparator on the list. But this comparator is only comparing two elements against each other without any context about their position in the list.
Expected behavior
The method httpHeaders.getAcceptableMediaTypes() should return the media types in correct order with application/json being the first etc...
Actual behavior
At the moment "text/plain" is being returned, probably because it has the most additional parameters.
How to Reproduce?
Define a rest resource that accepts multiple media types:
@produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN, "text/csv"})
then use httpHeaders to get the prefered media type from call,
In the rest call use the header "accept" "application/json,text/html; charset=UTF-8,text/plain; charset=UTF-8,/;q=0.8"
Output of uname -a or ver
No response
Output of java -version
No response
Quarkus version or git rev
3.29.2
Build tool (ie. output of mvnw --version or gradlew --version)
No response
Additional information
No response