Don't duplicate methods in Allow: header for 405 responses (#1029)
This commit is contained in:
parent
29164f023b
commit
9b6ddcddb9
2 changed files with 12 additions and 4 deletions
|
|
@ -394,14 +394,18 @@ func TestMuxNestedNotFound(t *testing.T) {
|
|||
func TestMethodNotAllowed(t *testing.T) {
|
||||
r := NewRouter()
|
||||
|
||||
r.Get("/hi", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Get("/hi", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Write([]byte("hi, get"))
|
||||
})
|
||||
|
||||
r.Head("/hi", func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Head("/hi", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Write([]byte("hi, head"))
|
||||
})
|
||||
|
||||
r.Get("/*", func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.Write([]byte("catch-all"))
|
||||
})
|
||||
|
||||
ts := httptest.NewServer(r)
|
||||
defer ts.Close()
|
||||
|
||||
|
|
|
|||
8
tree.go
8
tree.go
|
|
@ -479,7 +479,9 @@ func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node {
|
|||
if endpoints == mALL || endpoints == mSTUB {
|
||||
continue
|
||||
}
|
||||
rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints)
|
||||
if !slices.Contains(rctx.methodsAllowed, endpoints) {
|
||||
rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints)
|
||||
}
|
||||
}
|
||||
|
||||
// flag that the routing context found a route, but not a corresponding
|
||||
|
|
@ -525,7 +527,9 @@ func (n *node) findRoute(rctx *Context, method methodTyp, path string) *node {
|
|||
if endpoints == mALL || endpoints == mSTUB {
|
||||
continue
|
||||
}
|
||||
rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints)
|
||||
if !slices.Contains(rctx.methodsAllowed, endpoints) {
|
||||
rctx.methodsAllowed = append(rctx.methodsAllowed, endpoints)
|
||||
}
|
||||
}
|
||||
|
||||
// flag that the routing context found a route, but not a corresponding
|
||||
|
|
|
|||
Loading…
Reference in a new issue