mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 13:43:47 +03:00
caddyhttp: replace placeholders in map defaults (#5081)
This updates the map directive to replace placeholders in default values in the same way as matched values.
This commit is contained in:
parent
e3e8aabbcf
commit
61822f129b
2 changed files with 23 additions and 1 deletions
|
@ -169,7 +169,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
|
|||
|
||||
// fall back to default if no match or if matched nil value
|
||||
if len(h.Defaults) > destIdx {
|
||||
return h.Defaults[destIdx], true
|
||||
return repl.ReplaceAll(h.Defaults[destIdx], ""), true
|
||||
}
|
||||
|
||||
return nil, true
|
||||
|
|
|
@ -98,6 +98,28 @@ func TestHandler(t *testing.T) {
|
|||
"output": "testing",
|
||||
},
|
||||
},
|
||||
{
|
||||
reqURI: "/foo",
|
||||
handler: Handler{
|
||||
Source: "{http.request.uri.path}",
|
||||
Destinations: []string{"{output}"},
|
||||
Defaults: []string{"default"},
|
||||
},
|
||||
expect: map[string]any{
|
||||
"output": "default",
|
||||
},
|
||||
},
|
||||
{
|
||||
reqURI: "/foo",
|
||||
handler: Handler{
|
||||
Source: "{http.request.uri.path}",
|
||||
Destinations: []string{"{output}"},
|
||||
Defaults: []string{"{testvar}"},
|
||||
},
|
||||
expect: map[string]any{
|
||||
"output": "testing",
|
||||
},
|
||||
},
|
||||
} {
|
||||
if err := tc.handler.Provision(caddy.Context{}); err != nil {
|
||||
t.Fatalf("Test %d: Provisioning handler: %v", i, err)
|
||||
|
|
Loading…
Reference in a new issue