diff options
author | Francis Lavoie <[email protected]> | 2024-01-23 19:36:59 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-01-23 19:36:59 -0500 |
commit | 750d0b83319ac0ea6b7f057b8270c19404c3d6fa (patch) | |
tree | d0c3fb610cde8ae9d73a0a2caba94542af099770 /modules/caddyhttp/push | |
parent | 54823f52bc9aed66a1a37f820daf6e494181211a (diff) | |
download | caddy-750d0b83319ac0ea6b7f057b8270c19404c3d6fa.tar.gz caddy-750d0b83319ac0ea6b7f057b8270c19404c3d6fa.zip |
caddyfile: Normalize & flatten all unmarshalers (#6037)
Diffstat (limited to 'modules/caddyhttp/push')
-rw-r--r-- | modules/caddyhttp/push/caddyfile.go | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/modules/caddyhttp/push/caddyfile.go b/modules/caddyhttp/push/caddyfile.go index 963117c1c..07f6ccea7 100644 --- a/modules/caddyhttp/push/caddyfile.go +++ b/modules/caddyhttp/push/caddyfile.go @@ -44,63 +44,63 @@ func init() { // Placeholders are accepted in resource and header field // name and value and replacement tokens. func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { - handler := new(Handler) - - for h.Next() { - if h.NextArg() { - handler.Resources = append(handler.Resources, Resource{Target: h.Val()}) - } + h.Next() // consume directive name - // optional block - for outerNesting := h.Nesting(); h.NextBlock(outerNesting); { - switch h.Val() { - case "headers": - if h.NextArg() { - return nil, h.ArgErr() - } - for innerNesting := h.Nesting(); h.NextBlock(innerNesting); { - var err error + handler := new(Handler) - // include current token, which we treat as an argument here - args := []string{h.Val()} - args = append(args, h.RemainingArgs()...) + // inline resources + if h.NextArg() { + handler.Resources = append(handler.Resources, Resource{Target: h.Val()}) + } - if handler.Headers == nil { - handler.Headers = new(HeaderConfig) - } + // optional block + for h.NextBlock(0) { + switch h.Val() { + case "headers": + if h.NextArg() { + return nil, h.ArgErr() + } + for nesting := h.Nesting(); h.NextBlock(nesting); { + var err error - switch len(args) { - case 1: - err = headers.CaddyfileHeaderOp(&handler.Headers.HeaderOps, args[0], "", "") - case 2: - err = headers.CaddyfileHeaderOp(&handler.Headers.HeaderOps, args[0], args[1], "") - case 3: - err = headers.CaddyfileHeaderOp(&handler.Headers.HeaderOps, args[0], args[1], args[2]) - default: - return nil, h.ArgErr() - } + // include current token, which we treat as an argument here + args := []string{h.Val()} + args = append(args, h.RemainingArgs()...) - if err != nil { - return nil, h.Err(err.Error()) - } + if handler.Headers == nil { + handler.Headers = new(HeaderConfig) } - case "GET", "HEAD": - method := h.Val() - if !h.NextArg() { + switch len(args) { + case 1: + err = headers.CaddyfileHeaderOp(&handler.Headers.HeaderOps, args[0], "", "") + case 2: + err = headers.CaddyfileHeaderOp(&handler.Headers.HeaderOps, args[0], args[1], "") + case 3: + err = headers.CaddyfileHeaderOp(&handler.Headers.HeaderOps, args[0], args[1], args[2]) + default: return nil, h.ArgErr() } - target := h.Val() - handler.Resources = append(handler.Resources, Resource{ - Method: method, - Target: target, - }) - default: - handler.Resources = append(handler.Resources, Resource{Target: h.Val()}) + if err != nil { + return nil, h.Err(err.Error()) + } + } + + case "GET", "HEAD": + method := h.Val() + if !h.NextArg() { + return nil, h.ArgErr() } + target := h.Val() + handler.Resources = append(handler.Resources, Resource{ + Method: method, + Target: target, + }) + + default: + handler.Resources = append(handler.Resources, Resource{Target: h.Val()}) } } - return handler, nil } |