Skip to content

Commit 9fb4a15

Browse files
authored
update reverseMethodMap in RegisterMethod (#1022)
Fixes #1021.
1 parent 51c977c commit 9fb4a15

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

mux_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,26 @@ func TestCustomHTTPMethod(t *testing.T) {
17821782
if _, body := testRequest(t, ts, "BOO", "/hi", nil); body != "custom method" {
17831783
t.Fatal(body)
17841784
}
1785+
1786+
var expectRoutes = map[string]string{
1787+
"GET": "/",
1788+
"BOO": "/hi",
1789+
}
1790+
Walk(r, func(method string, route string, handler http.Handler, _ ...func(http.Handler) http.Handler) error {
1791+
r, ok := expectRoutes[method]
1792+
if !ok {
1793+
t.Fatalf("unexpected method %s", method)
1794+
}
1795+
if r != route {
1796+
t.Fatalf("expected route %s, got %s", r, route)
1797+
}
1798+
delete(expectRoutes, method)
1799+
1800+
return nil
1801+
})
1802+
if len(expectRoutes) != 0 {
1803+
t.Fatalf("missing expected methods: %v", expectRoutes)
1804+
}
17851805
}
17861806

17871807
func TestMuxMatch(t *testing.T) {

tree.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func RegisterMethod(method string) {
7171
}
7272
mt := methodTyp(2 << n)
7373
methodMap[method] = mt
74+
reverseMethodMap[mt] = method
7475
mALL |= mt
7576
}
7677

0 commit comments

Comments
 (0)