MCPcopy
hub / github.com/caddyserver/caddy / ProvisionHandlers

Method ProvisionHandlers

modules/caddyhttp/routes.go:160–185  ·  view source on GitHub ↗

ProvisionHandlers sets up all the handlers by loading the handler modules. Only call this method directly if you need to set up matchers and handlers separately without having to provision a second time; otherwise use Provision instead.

(ctx caddy.Context, metrics *Metrics)

Source from the content-addressed store, hash-verified

158// to set up matchers and handlers separately without having
159// to provision a second time; otherwise use Provision instead.
160func (r *Route) ProvisionHandlers(ctx caddy.Context, metrics *Metrics) error {
161 handlersIface, err := ctx.LoadModule(r, "HandlersRaw")
162 if err != nil {
163 return fmt.Errorf("loading handler modules: %v", err)
164 }
165 for _, handler := range handlersIface.([]any) {
166 r.Handlers = append(r.Handlers, handler.(MiddlewareHandler))
167 }
168
169 // Store metrics info for route-level instrumentation (applied once
170 // per route in wrapRoute, instead of per-handler which was redundant).
171 r.metrics = metrics
172 r.metricsCtx = ctx
173 if len(r.Handlers) > 0 {
174 r.handlerName = caddy.GetModuleName(r.Handlers[0])
175 }
176
177 // Make ProvisionHandlers idempotent by clearing the middleware field
178 r.middleware = []Middleware{}
179
180 // pre-compile the middleware handler chain
181 for _, midhandler := range r.Handlers {
182 r.middleware = append(r.middleware, wrapMiddleware(ctx, midhandler))
183 }
184 return nil
185}
186
187// Compile prepares a middleware chain from the route list.
188// This should only be done once during the request, just

Callers 3

ProvisionMethod · 0.95
ProvisionHandlersMethod · 0.45
ProvisionMethod · 0.45

Calls 2

wrapMiddlewareFunction · 0.85
LoadModuleMethod · 0.80

Tested by

no test coverage detected