diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-09 16:56:20 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-09 16:56:20 -0700 |
commit | 29315847a8e6c17503408ac74567942533fc3d48 (patch) | |
tree | 9c3c4092c9c4704c9fc89064b58ba1b8e219c8c9 /caddyconfig/httpcaddyfile | |
parent | 994b9033e96da270dca48ab01377431028c06b52 (diff) |
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.
Diffstat (limited to 'caddyconfig/httpcaddyfile')
-rw-r--r-- | caddyconfig/httpcaddyfile/httptype.go | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 64b93b0..33a37d3 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -318,10 +318,7 @@ func (st *ServerType) serversFromPairings( return nil, fmt.Errorf("server block %v: compiling matcher sets: %v", sblock.block.Keys, err) } - // if there are user-defined variables, then siteVarSubroute will - // wrap the handlerSubroute; otherwise handlerSubroute will be the - // site's primary subroute. - siteVarSubroute, handlerSubroute := new(caddyhttp.Subroute), new(caddyhttp.Subroute) + siteSubroute := new(caddyhttp.Subroute) // tls: connection policies and toggle auto HTTPS @@ -357,10 +354,10 @@ func (st *ServerType) serversFromPairings( // TODO: consolidate equal conn policies } - // vars: special routes that will have to wrap the normal handlers - // so that these variables can be used across their matchers too + // vars: make sure these are linked in first so future + // routes can use the variables they define for _, cfgVal := range sblock.pile["var"] { - siteVarSubroute.Routes = append(siteVarSubroute.Routes, cfgVal.Value.(caddyhttp.Route)) + siteSubroute.Routes = append(siteSubroute.Routes, cfgVal.Value.(caddyhttp.Route)) } // set up each handler directive - the order of the handlers @@ -437,28 +434,7 @@ func (st *ServerType) serversFromPairings( r.Value = route } - handlerSubroute.Routes = append(handlerSubroute.Routes, r.Value.(caddyhttp.Route)) - } - - // the route that contains the site's handlers will - // be assumed to be the sub-route for this site... - siteSubroute := handlerSubroute - - // ... unless, of course, there are variables that might - // be used by the site's matchers or handlers, in which - // case we need to nest the handlers in a sub-sub-route, - // and the variables go in the sub-route so the variables - // get evaluated first - if len(siteVarSubroute.Routes) > 0 { - subSubRoute := caddyhttp.Subroute{Routes: siteSubroute.Routes} - siteSubroute.Routes = append( - siteVarSubroute.Routes, - caddyhttp.Route{ - HandlersRaw: []json.RawMessage{ - caddyconfig.JSONModuleObject(subSubRoute, "handler", "subroute", warnings), - }, - }, - ) + siteSubroute.Routes = append(siteSubroute.Routes, r.Value.(caddyhttp.Route)) } siteSubroute.Routes = consolidateRoutes(siteSubroute.Routes) |