Unable to get 405 Method not supported status code, when requested method not found
Describe the bug Request to any other method(s), other then defined method, is not returning 405-"Method not supported" status code. Instead, returning 404-"Not found".
Sample
Assume that we have a Route with "/users/" path and with GET operation only.
Request GET /users/ --> this is valid and returning valid response. -- no issues.
Request POST /users/ --> this is return 404-"Not found", instead of 405-"Method not supported".
@satyam-bala do you use the "Method Route Predicate" ? if you use it, I think the 404 means it can't match the right route.
Using the default Predicate - RoutePredicateHandlerMapping.
More detailed logs: 2024-07-23T07:16:47.174Z DEBUG 1 --- [api-gateway] [or-http-epoll-6] o.s.w.s.adapter.HttpWebHandlerAdapter : [ae8db915-7] HTTP DELETE "/api/v1/test?orgId=111" 2024-07-23T07:16:47.175Z DEBUG 1 --- [api-gateway] [or-http-epoll-6] o.s.w.r.handler.SimpleUrlHandlerMapping : [ae8db915-7] Mapped to ResourceWebHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/]] 2024-07-23T07:16:47.177Z DEBUG 1 --- [api-gateway] [or-http-epoll-6] o.s.w.r.resource.ResourceWebHandler : [ae8db915-7] Resource not found 2024-07-23T07:16:47.181Z DEBUG 1 --- [api-gateway] [or-http-epoll-6] a.w.r.e.AbstractErrorWebExceptionHandler : [ae8db915-7] Resolved [NoResourceFoundException: 404 NOT_FOUND "No static resource api/v1/test."] for HTTP DELETE /api/v1/test 2024-07-23T07:16:47.182Z DEBUG 1 --- [api-gateway] [or-http-epoll-6] o.s.http.codec.json.Jackson2JsonEncoder : [ae8db915-7] Encoding [{timestamp=Tue Jul 23 07:16:47 GMT 2024, path=/api/v1/test, status=404, error=Not Found, requestId=a (truncated)...] 2024-07-23T07:16:47.183Z DEBUG 1 --- [api-gateway] [or-http-epoll-6] o.s.w.s.adapter.HttpWebHandlerAdapter : [ae8db915-7] Completed 404 NOT_FOUND
Please say the versions you are using and provide your configuration
Version: org.springframework.cloud:spring-cloud-starter-gateway:jar:4.1.5
Here is the Config:
server:
port: 8080
spring:
application:
name: api-gateway
cloud:
gateway:
routes:
- id: test-self-read-api
uri: http://test-api:8080/
predicates:
- Path=/api/v1/test/self
- Method=GET
- id: test-read-api
uri: http://test-api:8080/
predicates:
- Path=/api/v1/test/{id}
- Method=GET
Hi Any update on this ?
If you are using Circuit Breaker then check your fallback logic
Gateway doesn't provide this functionality and I don't think we can since http method is an optional part of a predicate. You could create another route that matches the not allowed methods and use a SetStatus filter.