You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is a route pattern with a different Method after the same pattern ( "OPTIONS /a/b
after GET /a/b") for which there is a middle-ware response, it gives 405. I guess it's related to gorilla#509
…
Versions
Go version: go1.11.5 linux/amd64
package version: 9536e4053d763b54d935f1ce731a315cfb42b979
…
Steps to Reproduce
Define a route /a/b with method GET
Define a route /a/{a} with method OPTIONS
Define middleware which gives 200 for defined options routes
It gives StatusMethodMismatch(405) instead of 200
If the steps 1 and 2 are reversed it gives 200
…
Expected behavior
The expected behaviour is to give 200
…
Code Snippets
mux_test.go
// testMiddleWare returns 200 on an OPTIONS request
func testOptionsMiddleWare(inner http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusOK)
return
}
inner.ServeHTTP(w, r)
})
}
// Passes if /a/{a} is defined first
func TestRouterOrder(t *testing.T) {
handler := func(w http.ResponseWriter, r *http.Request) {}
router := NewRouter()
router.Path("/a/b").Handler(http.HandlerFunc(handler)).Methods(http.MethodGet)
router.Path("/a/{a}").Handler(nil).Methods(http.MethodOptions)
router.Use(MiddlewareFunc(testOptionsMiddleWare))
w := NewRecorder()
req := newRequest(http.MethodOptions, "/a/b")
router.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("Expected status code 200 (got %d)", w.Code)
}
}
MIGRATED
From mux created by rkilingr: gorilla#515
Describe the bug
Versions
…
Steps to Reproduce
…
Expected behavior
…
Code Snippets
…
Possible Solution
The text was updated successfully, but these errors were encountered: