Browse code

api/server: Server.CreateMux: register debug endpoints with correct methods

The debug handlers were created for GET methods, but were registered for
any method;

curl -s -XGET --unix-socket /var/run/docker.sock http://localhost/debug/vars | jq -c .cmdline
["dockerd","--debug"]
curl -s -XPOST --unix-socket /var/run/docker.sock http://localhost/debug/vars | jq -c .cmdline
["dockerd","--debug"]
curl -s -XDELETE --unix-socket /var/run/docker.sock http://localhost/debug/vars | jq -c .cmdline
["dockerd","--debug"]

After this patch, they're only registered with the intended method, and a
404 is returned for incorrect ones;

curl -s -XGET --unix-socket /var/run/docker.sock http://localhost/debug/vars | jq -c .cmdline
["dockerd","--debug"]
curl -s -XPOST --unix-socket /var/run/docker.sock http://localhost/debug/vars
{"message":"page not found"}
curl -s -XDELETE --unix-socket /var/run/docker.sock http://localhost/debug/vars
{"message":"page not found"}

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/12/08 22:46:13
Showing 1 changed files
... ...
@@ -83,7 +83,7 @@ func (s *Server) CreateMux(routers ...router.Router) *mux.Router {
83 83
 	debugRouter := debug.NewRouter()
84 84
 	for _, r := range debugRouter.Routes() {
85 85
 		f := s.makeHTTPHandler(r.Handler(), r.Method()+" "+r.Path())
86
-		m.Path(r.Path()).Handler(f)
86
+		m.Path(r.Path()).Methods(r.Method()).Handler(f)
87 87
 	}
88 88
 
89 89
 	notFoundHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {