summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2022-03-18 17:08:23 -0400
committerGitHub <noreply@github.com>2022-03-18 15:08:23 -0600
commitc5fffb4ac2631f0b41a8e13b62925b9dc8346cb9 (patch)
treec63bee8e93dd3b7b7544e18602a8606c3a38570d /modules
parentdc4d147388547515f77447d594024386b732e7d4 (diff)
caddyfile: Support for raw token values; improve `map`, `expression` (#4643)
* caddyfile: Support for raw token values, improve `map`, `expression` * Applied code review comments * Rename RawVal to ValRaw Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/celmatcher.go6
-rw-r--r--modules/caddyhttp/map/caddyfile.go21
2 files changed, 9 insertions, 18 deletions
diff --git a/modules/caddyhttp/celmatcher.go b/modules/caddyhttp/celmatcher.go
index d7d55d8..0306f39 100644
--- a/modules/caddyhttp/celmatcher.go
+++ b/modules/caddyhttp/celmatcher.go
@@ -150,7 +150,11 @@ func (m MatchExpression) Match(r *http.Request) bool {
// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (m *MatchExpression) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
- m.Expr = strings.Join(d.RemainingArgs(), " ")
+ if d.CountRemainingArgs() > 1 {
+ m.Expr = strings.Join(d.RemainingArgsRaw(), " ")
+ } else {
+ m.Expr = d.Val()
+ }
}
return nil
}
diff --git a/modules/caddyhttp/map/caddyfile.go b/modules/caddyhttp/map/caddyfile.go
index a7f809b..8394b21 100644
--- a/modules/caddyhttp/map/caddyfile.go
+++ b/modules/caddyhttp/map/caddyfile.go
@@ -15,7 +15,6 @@
package maphandler
import (
- "strconv"
"strings"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
@@ -75,11 +74,12 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
// every other line maps one input to one or more outputs
in := h.Val()
var outs []interface{}
- for _, out := range h.RemainingArgs() {
- if out == "-" {
+ for h.NextArg() {
+ val := h.ScalarVal()
+ if val == "-" {
outs = append(outs, nil)
} else {
- outs = append(outs, specificType(out))
+ outs = append(outs, val)
}
}
@@ -108,16 +108,3 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
return handler, nil
}
-
-func specificType(v string) interface{} {
- if num, err := strconv.Atoi(v); err == nil {
- return num
- }
- if num, err := strconv.ParseFloat(v, 64); err == nil {
- return num
- }
- if bool, err := strconv.ParseBool(v); err == nil {
- return bool
- }
- return v
-}