Provision ensures that h is set up properly before use.
(ctx caddy.Context)
| 260 | |
| 261 | // Provision ensures that h is set up properly before use. |
| 262 | func (h *Handler) Provision(ctx caddy.Context) error { |
| 263 | eventAppIface, err := ctx.App("events") |
| 264 | if err != nil { |
| 265 | return fmt.Errorf("getting events app: %v", err) |
| 266 | } |
| 267 | h.events = eventAppIface.(*caddyevents.App) |
| 268 | h.ctx = ctx |
| 269 | h.logger = ctx.Logger() |
| 270 | h.connections = make(map[io.ReadWriteCloser]openConnection) |
| 271 | h.connectionsMu = new(sync.Mutex) |
| 272 | |
| 273 | // warn about unsafe buffering config |
| 274 | if h.RequestBuffers == -1 || h.ResponseBuffers == -1 { |
| 275 | h.logger.Warn("UNLIMITED BUFFERING: buffering is enabled without any cap on buffer size, which can result in OOM crashes") |
| 276 | } |
| 277 | |
| 278 | // start by loading modules |
| 279 | if h.TransportRaw != nil { |
| 280 | mod, err := ctx.LoadModule(h, "TransportRaw") |
| 281 | if err != nil { |
| 282 | return fmt.Errorf("loading transport: %v", err) |
| 283 | } |
| 284 | h.Transport = mod.(http.RoundTripper) |
| 285 | |
| 286 | // set default buffer sizes if applicable |
| 287 | if bt, ok := h.Transport.(BufferedTransport); ok { |
| 288 | reqBuffers, respBuffers := bt.DefaultBufferSizes() |
| 289 | if h.RequestBuffers == 0 { |
| 290 | h.RequestBuffers = reqBuffers |
| 291 | } |
| 292 | if h.ResponseBuffers == 0 { |
| 293 | h.ResponseBuffers = respBuffers |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | if h.LoadBalancing != nil && h.LoadBalancing.SelectionPolicyRaw != nil { |
| 298 | mod, err := ctx.LoadModule(h.LoadBalancing, "SelectionPolicyRaw") |
| 299 | if err != nil { |
| 300 | return fmt.Errorf("loading load balancing selection policy: %s", err) |
| 301 | } |
| 302 | h.LoadBalancing.SelectionPolicy = mod.(Selector) |
| 303 | } |
| 304 | if h.CBRaw != nil { |
| 305 | mod, err := ctx.LoadModule(h, "CBRaw") |
| 306 | if err != nil { |
| 307 | return fmt.Errorf("loading circuit breaker: %s", err) |
| 308 | } |
| 309 | h.CB = mod.(CircuitBreaker) |
| 310 | } |
| 311 | if h.DynamicUpstreamsRaw != nil { |
| 312 | mod, err := ctx.LoadModule(h, "DynamicUpstreamsRaw") |
| 313 | if err != nil { |
| 314 | return fmt.Errorf("loading upstream source module: %v", err) |
| 315 | } |
| 316 | h.DynamicUpstreams = mod.(UpstreamSource) |
| 317 | } |
| 318 | |
| 319 | // parse trusted proxy CIDRs ahead of time |
nothing calls this directly
no test coverage detected