Skip to content
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

List supported media types in HttpMediaTypeNotSupportedException when given invalid input media types #28062

Closed
dirweis opened this issue Feb 16, 2022 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@dirweis
Copy link

dirweis commented Feb 16, 2022

If I pass an unknown value in the Content-Type header (like e.g. This string) the getSupportedMediaTypes() returns falsely an empty list. If I don't pass this header (in case it is needed) the method works fine. Same when I pass a known value like e.g. application/xml. Can you fix that, please?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 16, 2022
@bclozel
Copy link
Member

bclozel commented Feb 16, 2022

Looking at the HttpMediaTypeNotSupportedException, we have two types of constructors for this class:

  • HttpMediaTypeNotSupportedException(MediaType, java.util.List<org.springframework.http.MediaType>) when the given media type is valid but not supported by the handler. We're providing the list of supported media types so that the client can know which types could be used instead
  • HttpMediaTypeNotSupportedException(java.lang.String) when the given media type cannot be parsed (a InvalidMediaTypeException has been thrown) and performing content negotiation doesn't make sense

We could argue that the list of supported media types could be useful still, but at that point the main problem is that the given media type is invalid and so is the request as a result.

Could you expand on why this information is needed in your case? What are you trying to implement, where are you getting this exception?

@bclozel bclozel added in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-feedback We need additional information before we can continue labels Feb 16, 2022
@dirweis
Copy link
Author

dirweis commented Feb 16, 2022

I agree that content negotiation won't work with own values but is this not a case for a fallback on the server-side to respond with 415 and let the client know which media types are supported?

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 16, 2022
@bclozel bclozel added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Feb 16, 2022
@bclozel bclozel added this to the 6.0.x milestone Feb 16, 2022
@bclozel
Copy link
Member

bclozel commented Feb 16, 2022

I don't see why we couldn't add that extra information in this case. Knowing more about your use case and how you found out about it would have helped. I'll schedule this as an enhancement.

@bclozel bclozel changed the title HttpMediaTypeNotSupportedException getSupportedMediaTypes() fails for unknown values in Content-Type header List supported media types in HttpMediaTypeNotSupportedException when given invalid input media types Feb 16, 2022
@rstoyanchev rstoyanchev modified the milestones: 6.0.x, 6.1.x Dec 9, 2022
@rstoyanchev rstoyanchev modified the milestones: 6.1.x, 6.0.5 Jan 16, 2023
@rstoyanchev rstoyanchev self-assigned this Jan 16, 2023
mdeinum pushed a commit to mdeinum/spring-framework that referenced this issue Jun 29, 2023
Add constructors to HttpMediaTypeNotSupportedException and
UnsupportedMediaTypeStatusException for a parse error that also accept
the list of supported media types to include in the response headers.

Closes spring-projectsgh-28062
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants