-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Content Negotiation with media type parameters: Method producing exact match of Accept content type is not called. #27999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
A similar problem seems to exist for the @RestController
@RequestMapping("/hal-documents")
class MyController {
@PostMapping(
consumes = ["""application/hal+json;profile="my-resource-v1""""],
produces = ["""application/hal+json;profile="my-resource-v1""""]
)
fun postVersion1(@RequestBody request : String) = "version-1"
@PostMapping(
consumes = ["""application/hal+json;profile="my-resource-v2""""],
produces = ["""application/hal+json;profile="my-resource-v2""""]
)
fun postVersion2(@RequestBody request : String) = "version-2";
} A request that provides a request body with the content type |
There is a prior, related discussion in this #17949 (comment). Generally speaking, a If So even though charset is not in the Accept header (and shouldn't be I think, see #22788), it's still considered a match, and so effectively there is one matching parameter for each mapping. It's unclear which is or should be a more specific match. More generally, given a full range of cases with 1 or more of the same or different parameters on either side, it would be hard to imagine a good solution for matching and sorting based on parameters. Note that for |
@rstoyanchev thanks for your fast response and for pointing out the discussion of #17949. I've not found this thread in my research.
Is there an easy way to provide the additional meaning of media type parameters to the framework? Somehow stating that the media type parameter should be part of content negotiation. Meaning that an
I agree that the Accept / Content-Type media type for "+json" types implicitly contains the UTF-8 charset as json is by default UTF-8 (see https://datatracker.ietf.org/doc/html/rfc7159#section-8.1) if not otherwise explicitly stated. If we follow this line of argumentation, we can also assume, that specifying a "+json"
I'll open a separate issue for the |
Short of something like the |
I'm working on an API that produces
application/hal+json
documents that use the media typeprofile
parameter to support versioning.The structure of the controller looks like this:
If I execute a request, which
Accept
-Header exactly matches the media type produced bygetV1
, the method is not being called. Instead, the request is being routed togetWithoutProfile
.This seems to be wrong. I would expect that the best matching method is being called. Routing works correctly if the
charset
parameter is removed from thegetWithoutProfile
method.Affects: 5.3.15
The text was updated successfully, but these errors were encountered: