daemon/server: Server.makeHTTPHandler: pass Route as argument

Pass the Route as a whole, instead of some of its properties; this
allows the method to act on additional information provided by the
route.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-09-16 10:32:04 +02:00
parent 81506ad8b1
commit 94309db0aa

View File

@@ -33,7 +33,9 @@ func (s *Server) UseMiddleware(m middleware.Middleware) {
s.middlewares = append(s.middlewares, m)
}
func (s *Server) makeHTTPHandler(handler httputils.APIFunc, operation string) http.HandlerFunc {
func (s *Server) makeHTTPHandler(r router.Route) http.HandlerFunc {
handler := r.Handler()
operation := r.Method() + " " + r.Path()
return otelhttp.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Define the context that we'll pass around to share info
// like the docker-request-id.
@@ -91,7 +93,7 @@ func (s *Server) CreateMux(ctx context.Context, routers ...router.Router) *mux.R
return m
}
log.G(ctx).WithFields(log.Fields{"method": r.Method(), "path": r.Path()}).Debug("Registering route")
f := s.makeHTTPHandler(r.Handler(), r.Method()+" "+r.Path())
f := s.makeHTTPHandler(r)
m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f)
m.Path(r.Path()).Methods(r.Method()).Handler(f)
}