-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Status is 404 Not Found instead of 405 Method Not Allowed #437
Labels
Comments
Thanks. Are you interested in submitting a PR that tackles this?
The challenge is that ef912dd and this are conflicting behaviour - you need
to track two "kinds" of matchErr (matchRouteErr, matchMethodErr?) in order
to handle this. That also won't solve host matches, etc.
…On Mon, Jan 7, 2019 at 7:36 AM Gregor Weckbecker ***@***.***> wrote:
*What version of Go are you running?*
go version go1.11.4 linux/amd64
*What version of gorilla/mux are you at?*
f3ff42f
<f3ff42f>
*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
<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)
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#437>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABIcGIp-QzB3drMj0VdT_YkSUDRLCYdks5vA01TgaJpZM4Zzg_P>
.
|
I will have a look into this and try to provide a PR. |
This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days. |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
What version of Go are you running?
What version of gorilla/mux are you at?
f3ff42f
Describe your problem
Currently the router returns
404
instead of405
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
The text was updated successfully, but these errors were encountered: