mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
caddyconfig: Support placeholders in HTTP loader
This commit is contained in:
parent
57a708d189
commit
ff137d17d0
1 changed files with 10 additions and 3 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue