From ce815471fee78e7357cf14e9fe27cfe26daa7cde Mon Sep 17 00:00:00 2001 From: Seebs Date: Thu, 1 Nov 2018 12:49:17 -0500 Subject: [PATCH] Drop now-superfluous methodNotAllowedHandler Long ago, the maintainers of gorilla/mux concluded that it was a "wontfix" to return StatusMethodNotAllowed instead of StatusNotFound for a method mismatch. Pilosa had a workaround for this for the most common case (GET requests to /index/{index}/query), and a TODO to address the other cases. While browsing the go-pilosa client code, I noticed that there is a test for roaring import support which relies on getting StatusMethodNotAllowed. But how can this work, if gorilla/mux doesn't do that? Answer: They started doing it in mid-2017, apparently: https://github.com/gorilla/mux/issues/271 Dropping this code changes the exact text of the message produced for that one case, but not the status code, and makes the behavior less confusing. --- http/handler.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/http/handler.go b/http/handler.go index 6007d72a8..1d5dee6f7 100644 --- a/http/handler.go +++ b/http/handler.go @@ -260,20 +260,10 @@ func newRouter(handler *Handler) *mux.Router { router.HandleFunc("/internal/shards/max", handler.handleGetShardsMax).Methods("GET").Name("GetShardsMax") // TODO: deprecate, but it's being used by the client router.HandleFunc("/internal/translate/data", handler.handleGetTranslateData).Methods("GET").Name("GetTranslateData") - // TODO: Apply MethodNotAllowed statuses to all endpoints. - // Ideally this would be automatic, as described in this (wontfix) ticket: - // https://github.com/gorilla/mux/issues/6 - // For now we just do it for the most commonly used handler, /query - router.HandleFunc("/index/{index}/query", handler.methodNotAllowedHandler).Methods("GET") - router.Use(handler.queryArgValidator) return router } -func (h *Handler) methodNotAllowedHandler(w http.ResponseWriter, _ *http.Request) { - http.Error(w, "method not allowed", http.StatusMethodNotAllowed) -} - // ServeHTTP handles an HTTP request. func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer func() {