caddyconfig: Support placeholders in HTTP loader

This commit is contained in:
Matthew Holt 2022-02-17 22:58:25 -07:00
parent 57a708d189
commit ff137d17d0
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5

View File

@ -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 {