@marcel91200 / caddy Mirror · read-only / commits / 29315847
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 14, 05:15 UTC

caddyfile: Use of vars no longer requires nesting in subroutes

This is because of our sequential handling logic which was recently merged; if vars is the first handler in the chain, it will be run before the next route's matchers are executed, so there's no need to nest the handlers anymore.

Matthew Holt committed Jan 9, 2020 at 16:56 UTC 29315847a8e6c17503408ac74567942533fc3d48
1 file changed +5 -29
caddyconfig/httpcaddyfile/httptype.go
+5 -29
@@ -318,10 +318,7 @@ func (st *ServerType) serversFromPairings(
318 return nil, fmt.Errorf("server block %v: compiling matcher sets: %v", sblock.block.Keys, err)
319 }
320
321 - // if there are user-defined variables, then siteVarSubroute will
322 - // wrap the handlerSubroute; otherwise handlerSubroute will be the
323 - // site's primary subroute.
324 - siteVarSubroute, handlerSubroute := new(caddyhttp.Subroute), new(caddyhttp.Subroute)
321 + siteSubroute := new(caddyhttp.Subroute)
322
323 // tls: connection policies and toggle auto HTTPS
324
@@ -357,10 +354,10 @@ func (st *ServerType) serversFromPairings(
354 // TODO: consolidate equal conn policies
355 }
356
360 - // vars: special routes that will have to wrap the normal handlers
361 - // so that these variables can be used across their matchers too
357 + // vars: make sure these are linked in first so future
358 + // routes can use the variables they define
359 for _, cfgVal := range sblock.pile["var"] {
363 - siteVarSubroute.Routes = append(siteVarSubroute.Routes, cfgVal.Value.(caddyhttp.Route))
360 + siteSubroute.Routes = append(siteSubroute.Routes, cfgVal.Value.(caddyhttp.Route))
361 }
362
363 // set up each handler directive - the order of the handlers
@@ -437,28 +434,7 @@ func (st *ServerType) serversFromPairings(
434 r.Value = route
435 }
436
440 - handlerSubroute.Routes = append(handlerSubroute.Routes, r.Value.(caddyhttp.Route))
441 - }
442 -
443 - // the route that contains the site's handlers will
444 - // be assumed to be the sub-route for this site...
445 - siteSubroute := handlerSubroute
446 -
447 - // ... unless, of course, there are variables that might
448 - // be used by the site's matchers or handlers, in which
449 - // case we need to nest the handlers in a sub-sub-route,
450 - // and the variables go in the sub-route so the variables
451 - // get evaluated first
452 - if len(siteVarSubroute.Routes) > 0 {
453 - subSubRoute := caddyhttp.Subroute{Routes: siteSubroute.Routes}
454 - siteSubroute.Routes = append(
455 - siteVarSubroute.Routes,
456 - caddyhttp.Route{
457 - HandlersRaw: []json.RawMessage{
458 - caddyconfig.JSONModuleObject(subSubRoute, "handler", "subroute", warnings),
459 - },
460 - },
461 - )
437 + siteSubroute.Routes = append(siteSubroute.Routes, r.Value.(caddyhttp.Route))
438 }
439
440 siteSubroute.Routes = consolidateRoutes(siteSubroute.Routes)