-
Notifications
You must be signed in to change notification settings - Fork 38.5k
RequestMappingInfoHandlerMapping.handleNoMatch throws 415 when it should throw 406 [SPR-14397] #18969
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
Rossen Stoyanchev commented 415 is the status code for the "Content-Type" of the request payload: 406 Not Acceptable refers to the representation requested with the "Accept" header for response: |
Nick commented
With these two endpoints:
This fails with a 415: POST /test, Content-Type: JSON, Accept: application/xml The first request should also return 406 - 415 shouldn't be raised because there is an endpoint that supports Content-Type: JSON but it can't produce application/xml. |
Rossen Stoyanchev commented Ah, I misunderstood then. I will have a closer look. |
Nick commented Thanks Rossen, I figured it might be difficult to verify so I submitted a repro project to make it easier. |
Rossen Stoyanchev commented Thanks for the repro project. I think we can improve the |
Rossen Stoyanchev commented I've pushed a commit that should fix the issue. Would you mind giving it a try with 4.3.1.BUILD-SNAPSHOT (from repo.spring.io/snapshots) when the next build is done? Thanks. |
Nick commented Just pulled down spring-core-4.3.1.BUILD-20160629.200020-43 and everything looks great, all of my tests are passing. Thanks Rossen. |
Rossen Stoyanchev commented Thanks for confirming and reporting the issue! |
Nick opened SPR-14397 and commented
When two methods have the same mapping but differ on what media types they consume, handleNoMatch is throwing a 415 Unsupported media type when it should be throwing 406 Not acceptable. In the following example, we have two methods that both produce JSON, but take different input formats:
The following requests fail with 415 when they should be 406:
This is because in my project, I also have an HttpMessageConverter that can produce XML. If I didn't, I would get a 406, since the sequence of events would be:
But since there is also an HttpMessageConverter that can write XML, #3 in the above sequence succeeds and an error message is printed in XML and an HTTP status of 415 is returned.
Affects: 4.3 GA
Issue Links:
The text was updated successfully, but these errors were encountered: