Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 21:45 UTC
caddyconfig: Support placeholders in HTTP loader
Matthew Holt committed
Feb 17, 2022 at 22:58 UTC
ff137d17d008b827d32876310e1179ec5003fef7
1 file changed
+10
-3
caddyconfig/httploader.go
+10
-3
@@ -71,21 +71,28 @@ func (HTTPLoader) CaddyModule() caddy.ModuleInfo {
71
72
// LoadConfig loads a Caddy config.
73
func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) {
74
+ repl := caddy.NewReplacer()
75
+
76
client, err := hl.makeClient(ctx)
77
if err != nil {
78
return nil, err
79
}
80
79
- method := hl.Method
81
+ method := repl.ReplaceAll(hl.Method, "")
82
if method == "" {
83
method = http.MethodGet
84
}
85
84
- req, err := http.NewRequest(method, hl.URL, nil)
86
+ url := repl.ReplaceAll(hl.URL, "")
87
+ req, err := http.NewRequest(method, url, nil)
88
if err != nil {
89
return nil, err
90
}
88
- req.Header = hl.Headers
91
+ for key, vals := range hl.Headers {
92
+ for _, val := range vals {
93
+ req.Header.Add(repl.ReplaceAll(key, ""), repl.ReplaceKnown(val, ""))
94
+ }
95
+ }
96
97
resp, err := client.Do(req)
98
if err != nil {