-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Return 405 instead of 404 when HTTP method is not supported [SPR-4927] #9602
Comments
Kenny MacLeod commented bump |
Juergen Hoeller commented This is unfortunately a consequence of our new general matching algorithm there: The dispatcher, when eventually generating a response, doesn't know that there would have been a handler for the same request - just with POST instead of GET. All it knows is that there was no matching handler method found. We'll revisit that in the context of Spring 3.0's general REST support, which will also refine the matching algorithm. Juergen |
Arjen Poutsma commented I suggest that 405 ("Method Not Allowed") is used instead. Seems most applicable. |
Arjen Poutsma commented This should work now. |
Paul Benedict commented What are the odds that someone will want to customize the error code? Can 405 be the default with a way to override it? Maybe another attribute on |
Arjen Poutsma commented You can override the method that sets the response code in the AnnotationMethodHandlerAdapter. That said, I strongly recommend using 405, conforming to the HTTP spec. |
Grzegorz Borkowski commented During testing 3.0 M3 I've found invalid behavior related to this.
In my tests, I got following restuls: |
Arjen Poutsma commented I think this might be related to #10401. I will investigate it now. |
Arjen Poutsma commented Should be fixed now. |
Tom Schober commented Using this controller and 3.0 M3:
} Is this still a bug in M3? |
Arjen Poutsma commented It might be. Could you try a recent snapshot, and see if that works better? |
Kenny MacLeod opened SPR-4927 and commented
Prior to the use of Spring 2.5
@RequestMapping
, if I wanted to limit my controller to accepting POST requests only, I simply injected POST into the controller, and a GET request would result in a very specific "this controller only support POST" error.When I use
@RequestMapping
(method=POST), however, and send a GET request to the controller, I get an entry in the logs saying "No matching handler method found for ... , method 'GET'", and a 404 is returned to the client.This seems like a step backwards to me. I only noticed because a client was accidentally sending GET requests to a POST-only controller, and the resulting 404 caused some confusion, running around and general pointing of fingers. A 404 doesn't seem to be the correct response.
I'd like to suggest 406 (NOT ACCEPTABLE), but that may cause even more confusion. Even a 500 would be preferably to a 404 here, i think.
Affects: 2.5.4
Issue Links:
@Controller
method order effects@RequestMapping
behavior in ways not expectedReferenced from: commits ba42594, 0a6cac5
The text was updated successfully, but these errors were encountered: