diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-22 09:43:42 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-22 09:43:42 -0700 |
commit | c6bddbfbe25b2123a1b53a7a705283d68bc4109a (patch) | |
tree | 169cf3493819504399eab1eafc8c77f76b6280d3 /modules | |
parent | 0742530d3d8c602c5d42115606ae0e05b577f3e9 (diff) |
http: Fix vars matcher
Diffstat (limited to 'modules')
-rw-r--r-- | modules/caddyhttp/vars.go | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/modules/caddyhttp/vars.go b/modules/caddyhttp/vars.go index d6c5a66..1208d9c 100644 --- a/modules/caddyhttp/vars.go +++ b/modules/caddyhttp/vars.go @@ -16,6 +16,7 @@ package caddyhttp import ( "context" + "fmt" "net/http" "github.com/caddyserver/caddy/v2" @@ -64,12 +65,23 @@ func (VarsMatcher) CaddyModule() caddy.ModuleInfo { // Match matches a request based on variables in the context. func (m VarsMatcher) Match(r *http.Request) bool { - vars := r.Context().Value(VarsCtxKey).(map[string]string) + vars := r.Context().Value(VarsCtxKey).(map[string]interface{}) repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer) for k, v := range m { keyExpanded := repl.ReplaceAll(k, "") valExpanded := repl.ReplaceAll(v, "") - if vars[keyExpanded] != valExpanded { + var varStr string + switch vv := vars[keyExpanded].(type) { + case string: + varStr = vv + case fmt.Stringer: + varStr = vv.String() + case error: + varStr = vv.Error() + default: + varStr = fmt.Sprintf("%v", vv) + } + if varStr != valExpanded { return false } } |