diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-02-16 22:24:20 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-02-16 22:24:20 -0700 |
commit | 23cc26d585bfbbe06ae8d2f46fa64956e368baac (patch) | |
tree | db3212f2e97f5796383990bea68319b669f8badf /caddyconfig/httpcaddyfile/directives.go | |
parent | bc2e406572e9af290469b2d4d58974ac99c0b492 (diff) |
httpcaddyfile: 'handle_errors' directive
Not sure I love the name of the directive; might change it later.
Diffstat (limited to 'caddyconfig/httpcaddyfile/directives.go')
-rw-r--r-- | caddyconfig/httpcaddyfile/directives.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index 035dcbe..3c03d30 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -37,6 +37,7 @@ var directiveOrder = []string{ "uri_replace", "try_files", + // middleware handlers that typically wrap responses "basicauth", "header", "request_header", @@ -46,6 +47,7 @@ var directiveOrder = []string{ "handle", "route", + // handlers that typically respond to requests "respond", "reverse_proxy", "php_fastcgi", @@ -291,6 +293,37 @@ func sortRoutes(routes []ConfigValue) { }) } +// parseSegmentAsSubroute parses the segment such that its subdirectives +// are themselves treated as directives, from which a subroute is built +// and returned. +func parseSegmentAsSubroute(h Helper) (caddyhttp.MiddlewareHandler, error) { + var allResults []ConfigValue + for h.Next() { + for nesting := h.Nesting(); h.NextBlock(nesting); { + dir := h.Val() + + dirFunc, ok := registeredDirectives[dir] + if !ok { + return nil, h.Errf("unrecognized directive: %s", dir) + } + + subHelper := h + subHelper.Dispenser = h.NewFromNextSegment() + + results, err := dirFunc(subHelper) + if err != nil { + return nil, h.Errf("parsing caddyfile tokens for '%s': %v", dir, err) + } + for _, result := range results { + result.directive = dir + allResults = append(allResults, result) + } + } + return buildSubroute(allResults, h.groupCounter) // TODO: should we move this outside the loop? + } + return nil, nil +} + // serverBlock pairs a Caddyfile server block // with a "pile" of config values, keyed by class // name. |