mux
                                
                                 mux copied to clipboard
                                
                                    mux copied to clipboard
                            
                            
                            
                        When I use the subrouter() method, Methods() only works on the last endpoint, and other than the last endpoint, the rest of the endpoints give a 404 instead of a 405 with the unrelated http method.
Is there an existing issue for this?
- [X] I have searched the existing issues
Current Behavior
When I use the subrouter() method, Methods() only works on the last endpoint, and other than the last endpoint, the rest of the endpoints give a 404 instead of a 405 with the unrelated http method.
last endpoint :
other endpoints:
Expected Behavior
No response
Steps To Reproduce
No response
Anything else?
No response
Does https://github.com/gorilla/mux/pull/748 fix this for you?
Does #748 fix this for you?
no!
This appears to have been broken by https://github.com/gorilla/mux/pull/712, which clears a 405 error when a subsequent route matches in any part. The logic here is tricky: the desire is that if
Route 1: POST "/users/{id}".
Route 2: GET "/users/{id}", parameters: "id": "[0-9]+".
are configured, then GET "/users/-2" returns a 404, not a 405, because while it matches route 1 with a method error, it is a "better" match to route 2 with a parameter validation error.
But this logic then also applies to prefix matching in a sub router: the prefix match is the first matcher in the sequence, and a subsequent route that matches the prefix but is otherwise clearly not a match will clear an existing 405. Unfortunately I don't know the mux internals well enough to suggest a fix, but it seems like if the check from #712 is desired, it shouldn't apply to subroute matchers.