diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-09-10 19:21:52 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-09-10 19:21:52 -0600 |
commit | 2459c292a4d6fb0552eb9be3cecd955093ed853b (patch) | |
tree | 5f10e9c5d8e9250e83f7282e8d57d386cb54e8a6 /modules/caddyhttp | |
parent | 0cf592fa2e0d2fff8e9379095bbe17f7c8cbd4f2 (diff) |
caddyfile: Improve Dispenser.NextBlock() to support nesting
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r-- | modules/caddyhttp/encode/caddyfile.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/fileserver/caddyfile.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/fileserver/matcher.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/headers/caddyfile.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/matchers.go | 3 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/caddyfile.go | 5 | ||||
-rw-r--r-- | modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go | 52 | ||||
-rw-r--r-- | modules/caddyhttp/staticresp.go | 2 | ||||
-rw-r--r-- | modules/caddyhttp/templates/caddyfile.go | 2 |
9 files changed, 38 insertions, 34 deletions
diff --git a/modules/caddyhttp/encode/caddyfile.go b/modules/caddyhttp/encode/caddyfile.go index 5762bd3..d23eab9 100644 --- a/modules/caddyhttp/encode/caddyfile.go +++ b/modules/caddyhttp/encode/caddyfile.go @@ -67,7 +67,7 @@ func (enc *Encode) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { enc.EncodingsRaw[arg] = caddyconfig.JSON(encoding, nil) } - for d.NextBlock() { + for d.NextBlock(0) { name := d.Val() mod, err := caddy.GetModule("http.encoders." + name) if err != nil { diff --git a/modules/caddyhttp/fileserver/caddyfile.go b/modules/caddyhttp/fileserver/caddyfile.go index b7cb311..b50c166 100644 --- a/modules/caddyhttp/fileserver/caddyfile.go +++ b/modules/caddyhttp/fileserver/caddyfile.go @@ -43,7 +43,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) return nil, h.ArgErr() } - for h.NextBlock() { + for h.NextBlock(0) { switch h.Val() { case "hide": fsrv.Hide = h.RemainingArgs() diff --git a/modules/caddyhttp/fileserver/matcher.go b/modules/caddyhttp/fileserver/matcher.go index fde086e..4a7f657 100644 --- a/modules/caddyhttp/fileserver/matcher.go +++ b/modules/caddyhttp/fileserver/matcher.go @@ -69,7 +69,7 @@ func (MatchFile) CaddyModule() caddy.ModuleInfo { // func (m *MatchFile) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { for d.Next() { - for d.NextBlock() { + for d.NextBlock(0) { switch d.Val() { case "root": if !d.NextArg() { diff --git a/modules/caddyhttp/headers/caddyfile.go b/modules/caddyhttp/headers/caddyfile.go index 5eaf064..12ec8a0 100644 --- a/modules/caddyhttp/headers/caddyfile.go +++ b/modules/caddyhttp/headers/caddyfile.go @@ -49,7 +49,7 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) } // if not, they should be in a block - for h.NextBlock() { + for h.NextBlock(0) { if hasArgs { return nil, h.Err("cannot specify headers in both arguments and block") } diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index 4d0eea5..23047d0 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -258,6 +258,9 @@ func (MatchHeader) CaddyModule() caddy.ModuleInfo { // UnmarshalCaddyfile implements caddyfile.Unmarshaler. func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { + if *m == nil { + *m = make(map[string][]string) + } for d.Next() { var field, val string if !d.Args(&field, &val) { diff --git a/modules/caddyhttp/reverseproxy/caddyfile.go b/modules/caddyhttp/reverseproxy/caddyfile.go index ffa3ca0..56b3a5a 100644 --- a/modules/caddyhttp/reverseproxy/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/caddyfile.go @@ -81,7 +81,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { }) } - for d.NextBlock() { + for d.NextBlock(0) { switch d.Val() { case "to": args := d.RemainingArgs() @@ -343,7 +343,6 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if !ok { return d.Errf("transport module '%s' is not a Caddyfile unmarshaler", mod.Name) } - d.Next() // consume the module name token err = unm.UnmarshalCaddyfile(d.NewFromNextTokens()) if err != nil { return err @@ -377,7 +376,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { // } // func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { - for d.NextBlock() { + for d.NextBlock(0) { switch d.Val() { case "read_buffer": if !d.NextArg() { diff --git a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go index 1476d60..fd82c5a 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go @@ -39,32 +39,34 @@ func init() { // } // func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { - for d.NextBlock() { - switch d.Val() { - case "root": - if !d.NextArg() { - return d.ArgErr() + for d.Next() { + for d.NextBlock(0) { + switch d.Val() { + case "root": + if !d.NextArg() { + return d.ArgErr() + } + t.Root = d.Val() + + case "split": + if !d.NextArg() { + return d.ArgErr() + } + t.SplitPath = d.Val() + + case "env": + args := d.RemainingArgs() + if len(args) != 2 { + return d.ArgErr() + } + if t.EnvVars == nil { + t.EnvVars = make(map[string]string) + } + t.EnvVars[args[0]] = args[1] + + default: + return d.Errf("unrecognized subdirective %s", d.Val()) } - t.Root = d.Val() - - case "split": - if !d.NextArg() { - return d.ArgErr() - } - t.SplitPath = d.Val() - - case "env": - args := d.RemainingArgs() - if len(args) != 2 { - return d.ArgErr() - } - if t.EnvVars == nil { - t.EnvVars = make(map[string]string) - } - t.EnvVars[args[0]] = args[1] - - default: - return d.Errf("unrecognized subdirective %s", d.Val()) } } return nil diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go index 942459b..21ff9d5 100644 --- a/modules/caddyhttp/staticresp.go +++ b/modules/caddyhttp/staticresp.go @@ -57,7 +57,7 @@ func (s *StaticResponse) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if d.Args(&statusCodeStr) { s.StatusCode = WeakString(statusCodeStr) } - for d.NextBlock() { + for d.NextBlock(0) { switch d.Val() { case "body": if s.Body != "" { diff --git a/modules/caddyhttp/templates/caddyfile.go b/modules/caddyhttp/templates/caddyfile.go index 1336a60..5dc124f 100644 --- a/modules/caddyhttp/templates/caddyfile.go +++ b/modules/caddyhttp/templates/caddyfile.go @@ -34,7 +34,7 @@ func init() { func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { t := new(Templates) for h.Next() { - for h.NextBlock() { + for h.NextBlock(0) { switch h.Val() { case "mime": t.MIMETypes = h.RemainingArgs() |