-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix content negotiation content-type check for InputFormatter #3138
Comments
For example, I set: formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("*/*")); and I get But it works if I set: formatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/plain")); Is this behavior expected? |
It's possible there's a bug in how |
Put another way, |
Thanks @dougbu, but it was only an example. I think that an |
Do you have a concrete example that fails which doesn't involve Note what you're doing with the catch-all formatter (i.e. that accepts |
Thanks for your help @dougbu, since I need to ignore request content type, in my project I will override BUT, I am pretty sure that I am not understanding how to InputFormaters deal with It is not necessary a small project because there are already a test. In my opinion that test is wrong because it says that if request's CC: @harshgMSFT |
Looks like the IsSubset check is backwards - we should check that the request media type is a subset of the supported media type, not the other way around. |
Yes, the check is incorrect. Some non-exact matches start working after reversing it. None of the in-box input formatters support wildcard media types or subtypes. This reduces the impact slightly. Confirmed the Web.API 3 check matches what we have in MVC 6. See that version's |
Moving to early in RC1. The reversed check hid a couple of other bugs. While I have an implementation that covers most issues, we've revised the design to improve correctness, especially around formatter selection. Will take a bit more work... |
- aspnet/Mvc#3138 part 1/2 - check parameters with same polarity as type and subtype - ignore quality factors - bug was obscured because MVC has no formatters supporting wildcard media types nits: - add doc comments - spelling - correct typo in a `project.json` file
…ove one conneg fallback - #3138 part 2/2 - request's Content-Type header must be a subset of what an `IInputFormatter` can consume - `[Consumes]` is similar - what an `IOutputFormatter` produces must be a subset of the request's Accept header - `FormatFilter` and `ObjectResult` are similar - `ObjectResult` no longer falls back to `Content-Type` header if no `Accept` value is acceptable - left `WebApiCompatShim` code alone for consistency with down-level `System.Net.Http.Formatting` - correct tests to match new behaviour - do not test `Accept` values containing a `charset` parameter; that case is not valid WIP: - four test failures; something about comparing media types w/ charset included - why do some localization tests fail in VS? nits: - add `InputFormatterTests` - add / update comments and doc comments - correct xUnit attributes in `ActionResultTest`; odd it doesn't show up in command-line runs
- aspnet/Mvc#3138 part 1/2 - check parameters with same polarity as type and subtype - ignore quality factors - bug was obscured because MVC has no formatters supporting wildcard media types nits: - add doc comments - spelling - correct typo in a `project.json` file
…ove one conneg fallback - #3138 part 2/2 - request's Content-Type header must be a subset of what an `IInputFormatter` can consume - `[Consumes]` is similar - what an `IOutputFormatter` produces must be a subset of the request's Accept header - `FormatFilter` and `ObjectResult` are similar - `ObjectResult` no longer falls back to `Content-Type` header if no `Accept` value is acceptable - left `WebApiCompatShim` code alone for consistency with down-level `System.Net.Http.Formatting` - correct tests to match new behaviour - do not test `Accept` values containing a `charset` parameter; that case is not valid WIP: - four test failures; something about comparing media types w/ charset included - why do some localization tests fail in VS? nits: - add `InputFormatterTests` - add / update comments and doc comments - correct xUnit attributes in `ActionResultTest`; odd it doesn't show up in command-line runs
From InputFormatter.cs
If I am not wrong, to be able to read a request,
requestContentType
should be a subset of any ofInputFormatter
'sSupportedMediaTypes
.The text was updated successfully, but these errors were encountered: