-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
What version of Go are you running?
go version go1.11.4 linux/amd64
What version of gorilla/mux are you at?
Describe your problem
Currently the router returns 404
instead of 405
if the path matches but not the method. This is only the case if another not matching route was registered after the matching one.
This issues seems to be introduced through the changes in ef912dd .
Paste a minimal, runnable, reproduction of your issue below
func TestMethodNotAllowed(t *testing.T) {
router := NewRouter()
router.HandleFunc("/thing", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }).Methods(http.MethodGet)
router.HandleFunc("/something", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) }).Methods(http.MethodPost)
w := NewRecorder()
req := newRequest(http.MethodPut, "/thing")
router.ServeHTTP(w, req)
if w.Code != 405 {
t.Fatalf("Expected status code 405 (got %d)", w.Code)
}
}