From ff137d17d008b827d32876310e1179ec5003fef7 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Thu, 17 Feb 2022 22:58:25 -0700 Subject: caddyconfig: Support placeholders in HTTP loader --- caddyconfig/httploader.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'caddyconfig') diff --git a/caddyconfig/httploader.go b/caddyconfig/httploader.go index 396e153..e4d8159 100644 --- a/caddyconfig/httploader.go +++ b/caddyconfig/httploader.go @@ -71,21 +71,28 @@ func (HTTPLoader) CaddyModule() caddy.ModuleInfo { // LoadConfig loads a Caddy config. func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) { + repl := caddy.NewReplacer() + client, err := hl.makeClient(ctx) if err != nil { return nil, err } - method := hl.Method + method := repl.ReplaceAll(hl.Method, "") if method == "" { method = http.MethodGet } - req, err := http.NewRequest(method, hl.URL, nil) + url := repl.ReplaceAll(hl.URL, "") + req, err := http.NewRequest(method, url, nil) if err != nil { return nil, err } - req.Header = hl.Headers + for key, vals := range hl.Headers { + for _, val := range vals { + req.Header.Add(repl.ReplaceAll(key, ""), repl.ReplaceKnown(val, "")) + } + } resp, err := client.Do(req) if err != nil { -- cgit v1.2.3