diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2021-10-19 12:25:36 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2021-10-19 12:25:36 -0600 |
commit | a2119c09e95eeb871c2b30046f596d61257b108c (patch) | |
tree | 72ceea264c468dc2d06f4ab3232ef904f157def2 /modules/caddyhttp/map/map.go | |
parent | 062657d0d80aa1c2e3af51414db634f49c9a03a0 (diff) |
map: Fix 95c03506 (avoid repeated expansions)
Diffstat (limited to 'modules/caddyhttp/map/map.go')
-rw-r--r-- | modules/caddyhttp/map/map.go | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/modules/caddyhttp/map/map.go b/modules/caddyhttp/map/map.go index 670a55b..8394955 100644 --- a/modules/caddyhttp/map/map.go +++ b/modules/caddyhttp/map/map.go @@ -131,27 +131,21 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt // find the first mapping matching the input and return // the requested destination/output value for _, m := range h.Mappings { - if m.re != nil { - if m.re.MatchString(input) { - if output := m.Outputs[destIdx]; output == nil { - continue - } else { - var result []byte - for _, submatches := range m.re.FindAllStringSubmatchIndex(input, -1) { - result = m.re.ExpandString(result, m.Outputs[destIdx].(string), input, submatches) - } - output = string(result) - return output, true - } - } + output := m.Outputs[destIdx] + if output == nil { continue } - if input == m.Input { - if output := m.Outputs[destIdx]; output == nil { + if m.re != nil { + var result []byte + matches := m.re.FindStringSubmatchIndex(input) + if matches == nil { continue - } else { - return output, true } + result = m.re.ExpandString(result, output.(string), input, matches) + return string(result), true + } + if input == m.Input { + return output, true } } |