@marcel91200 / caddy Mirror · read-only / commits / 3553cfb6
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 21:00 UTC

caddyhttp: remove redundant middleware next copy (#7217)

Max Celant committed Sep 1, 2025 at 10:30 UTC 3553cfb6adb2954a53d559c1841c8072b9921e61
1 file changed +2 -14
modules/caddyhttp/routes.go
+2 -14
@@ -302,13 +302,7 @@ func wrapRoute(route Route) Middleware {
302
303 // wrapMiddleware wraps mh such that it can be correctly
304 // appended to a list of middleware in preparation for
305 -// compiling into a handler chain. We can't do this inline
306 -// inside a loop, because it relies on a reference to mh
307 -// not changing until the execution of its handler (which
308 -// is deferred by multiple func closures). In other words,
309 -// we need to pull this particular MiddlewareHandler
310 -// pointer into its own stack frame to preserve it so it
311 -// won't be overwritten in future loop iterations.
305 +// compiling into a handler chain.
306 func wrapMiddleware(ctx caddy.Context, mh MiddlewareHandler, metrics *Metrics) Middleware {
307 handlerToUse := mh
308 if metrics != nil {
@@ -317,18 +311,12 @@ func wrapMiddleware(ctx caddy.Context, mh MiddlewareHandler, metrics *Metrics) M
311 }
312
313 return func(next Handler) Handler {
320 - // copy the next handler (it's an interface, so it's
321 - // just a very lightweight copy of a pointer); this
322 - // is a safeguard against the handler changing the
323 - // value, which could affect future requests (yikes)
324 - nextCopy := next
325 -
314 return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
315 // EXPERIMENTAL: Trace each module that gets invoked
316 if server, ok := r.Context().Value(ServerCtxKey).(*Server); ok && server != nil {
317 server.logTrace(handlerToUse)
318 }
331 - return handlerToUse.ServeHTTP(w, r, nextCopy)
319 + return handlerToUse.ServeHTTP(w, r, next)
320 })
321 }
322 }