Skip to content

Return 405 instead of 404 when HTTP method is not supported [SPR-4927] #9602

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits ba42594, 0a6cac5

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions