-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Jose Montoya opened SPR-17133 and commented
At Rossen Stoyanchev's request I'm creating this ticket with the intention to put forward a cleaner description of use cases to maybe facilitate discussion. This issue that has been argued before in #17949 and #15531 and sprung an atom specific one #21578. There's also a StackOverflow question related to this topic here.
As shown by RFC 7231 Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content Section 5.3.2 Accept, media type parameters are to be included in the content negotiation process. Even if perhaps not called out explicitly in that section it is unarguably most evident that parameters participate in the process from the example in Page 39, where text/plain;format=flowed is considered independently from text/plain. If we have consensus with that claim then we can move to some use cases. Following the logic from the RFC, but without adding quality attributes at this point:
Setup:
For a given resource the server explicitly Produces type/sub; param1=foo only, which is implicitly included in type/sub and type/*
Use case 1, sub-type wildcard:
The client Accepts type/*
The server should return the content as identified by type/sub; param1=foo, as it's the most specific one included.
Use case 2, specific sub-type:
The client Accepts type/sub
Same as UC-1.
Use case 3, specific param match:
The client Accepts type/sub; param1=foo
The server should return the content as identified by type/sub; param1=foo, as it's an exact match.
Use case 4, specific param no match:
The client Accepts type/sub; param1=bar
The server should return a 406 (Not Acceptable), the param1 values are not equal.
Use case 5, multiple specific param no match:
The client Accepts type/sub; param1=foo; param2=bar
The server should return a 406 (Not Acceptable), the param1 vales are equal, but param2 means the client only accepts something more specific than what the server produces. What the client wants does not include what the server produces.
First issue:
In spring-core/MimeType there are two methods for comparing media types isCompatibleWith and includes, none of them take into consideration parameters. UC-4 and UC-5 currently fail by returning 200 (OK) with the content of type/sub; param1=foo but headers Content-Type=type/sub; param1=bar and Content-Type=type/sub; param1=foo; param2=bar, respectively. This is obviously erroneous behavior.
Fix:
MimeType.isCompatibleWith should be enhanced to consider parameters as follows: "Parameters are incompatible only when they contain the same parameter with different values." MimeType.includes should be enhanced to consider parameters as follows: "Parameters are not included when this MimeType contains more parameters than the supplied, when this contains a parameter that the supplied does not, or when they both contain the same parameter with different values." This would not be inconsistent with both methods' current implementation.
Second issue
spring-webmvc/ProducesRequestCondition's matchMediaType method utilizes isCompatibleWith which is a symmetric comparison, ie. even if we introduced parameters into its logic, UC-5 would fail by returning 200 (OK) with the content of type/sub; param1=foo but with header Content-Type=type/sub; param1=foo; param2=bar. This should be an asymmetric comparison because even though two media types may be mutually compatible the client may receive something that is not included by what it is explicitly requesting.
Fix:
ProducesRequestCondition.matchMediaType should be modified to use the enhanced includes instead of isCompatibleWith.
Affects: 5.1 RC1
Reference URL: #15531
Issue Links:
- Support for the "type" parameter for Atom Feed/Entry message conversion [SPR-17040] #21578 Support for the "type" parameter for Atom Feed/Entry message conversion
Referenced from: pull request #1920
1 votes, 3 watchers