diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2022-02-17 22:58:25 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2022-02-17 22:58:25 -0700 |
commit | ff137d17d008b827d32876310e1179ec5003fef7 (patch) | |
tree | fc8535219d3d483b208a6f83b20702c44d883f93 | |
parent | 57a708d189cfe4ccc20ae92df95dd35e52a434a8 (diff) |
caddyconfig: Support placeholders in HTTP loader
-rw-r--r-- | caddyconfig/httploader.go | 13 |
1 files changed, 10 insertions, 3 deletions
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 { |