From a2119c09e95eeb871c2b30046f596d61257b108c Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 19 Oct 2021 12:25:36 -0600 Subject: map: Fix 95c03506 (avoid repeated expansions) --- modules/caddyhttp/map/map.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'modules/caddyhttp/map/map.go') 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 } } -- cgit v1.2.3