-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Benedict Adamson opened SPR-13365 and commented
The
org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor
class does not respect media-type parameters when doing content negotiation. In the writeWithMessageConverters
method, if a requestedType
has a non empty MimeType.getParameters()
map, those parameters have no effect on which type is the selectedMediaType
. I believe that HTTP standard conformance requires that those parameters do have an effect on content negotiation.
The cause of this seems to be that writeWithMessageConverters
uses MimeType.isCompatibleWith(MimeType)
, which ignores the parameters, and then (indirectly) sorts the produceable media types using MediaType.SPECIFICITY_COMPARATOR
, which also ignores the parameters.
Worse still, if the selectedMediaType
(the supported media type of the chosen HTTP message converter) differs from the requested type only in the media-type parameters, the Content-Type
header of the response will contain the requested media type even though the response body is actually of the selectedMediaType
.
The cause of that seems to be that the AbstractMessageConverterMethodProcessor.getMostSpecificMediaType(MediaType, MediaType)
chooses the acceptType
rather than the produceTypeToUse
when the two types have equal specificity, according to the MediaType.SPECIFICITY_COMPARATOR
, and that comparator ignores the media-type parameters.
Affects: 4.1 GA
Issue Links:
- Content negotiation ignores media type parameters [SPR-10903] #15531 Content negotiation ignores media type parameters ("duplicates")