Skip to content
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

Closed
g-w opened this issue Jan 7, 2019 · 4 comments
Closed

Status is 404 Not Found instead of 405 Method Not Allowed #437

g-w opened this issue Jan 7, 2019 · 4 comments
Labels

Comments

@g-w
Copy link
Contributor

g-w commented Jan 7, 2019

What version of Go are you running?

go version go1.11.4 linux/amd64

What version of gorilla/mux are you at?

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 .

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)
	}
}
@elithrar
Copy link
Contributor

elithrar commented Jan 7, 2019 via email

@g-w
Copy link
Contributor Author

g-w commented Jan 7, 2019

I will have a look into this and try to provide a PR.

@g-w
Copy link
Contributor Author

g-w commented Jan 7, 2019

@elithrar I've created a PR #438.

@stale
Copy link

stale bot commented Mar 8, 2019

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.

@stale stale bot added the stale label Mar 8, 2019
@stale stale bot closed this as completed Mar 15, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants