-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[BUG] MethodNotAllowedHandler does not work for subrouter with different routes #739
Comments
I have the same issue, thank you for raising it. When I GET a path that only has a POST handler, I get the different behaviour. It used to be StatusMethodNotAllowed, now it's 404. |
Maybe I can help. Can I take a look into this? |
@mateusmarquezini I have assigned the issue to you, ping me if you need any assistance and thanks for volunteering! |
When a path with specific query params does not match we should return a ErrMethodMismatch instead of ErrNotFound
I have created a PR for this. Basically what we need to do is to remove the else statement on the route mismatch. If we have a route with specific query params and we call it with wrong query params, this is not a route not found error but a route mismatch error. If I understood something wrong on this please tell me!! |
Hi, all. I think the solution #746 proposed by @marcelom97 is not quite correct, as it completely cancels the earlier fix #712. I propose to make the following changes #748. This solution allows correct handling of errors related to invalid query parameters described in #704 and preserves the possibility of receiving ErrMethodMismatch for subrouter as well. |
Hey @BlasterAlex, |
Hi, @marcelom97. The problem is now we are not handling the case when query params are invalid. And in this case we get error 405 when we should have 404. Why in this case you think we should have this error and not 404? Line 2098 in 737cec6
Query params don't match the expected regular expression, so we shouldn't go to the request method check. |
@BlasterAlex I added some test cases to demonstrate the errors returned when the query params does not match on my PR#746
|
I apologize, but the fact that your cases work doesn't negate the fact that the edited old test doesn't work as expected) Why was it necessary to change the expected error from ErrNotFound to ErrMethodMismatch? Router.Match method call here should still return ErrNotFound. |
Is there an existing issue for this?
Current Behavior
Starting with mux
v1.8.1
we encountered the following problem, which was not present in previous versions of the library.If there are several routes in one subrouter, for example
/api
and/api/{id}
MethodNotAllowedHandler does not work and NotFoundHandler is used by default.An example test to reproduce the bug is shown below. The bug is not reproduced if:
/api
for example)/api/{id}
before HandleFunc for/api
in the codeAfter examining the modified code, it was found out that the problem is related to the addition of this else condition:
https://github.com/gorilla/mux/blob/v1.8.1/route.go#L70-L78
Since now the result of the Route.Match function depends on which Route was processed last (the value of match.MatchErr by reference is updated).
Expected Behavior
Result 405 Method Not Allowed
Steps To Reproduce
Anything else?
No response
The text was updated successfully, but these errors were encountered: