@marcel91200 / caddy Mirror · read-only / commits / 037dc23c
Fork 0

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, 10:30 UTC

admin: Use replacer on listen addresses (#5071)

* admin: use replacer on listen address * admin: consolidate replacer logic

Cory Cooper committed Sep 29, 2022 at 10:24 UTC 037dc23cad3848050dc1e6f4dfdabeb6ea190fa7
1 file changed +6 -3
admin.go
+6 -3
@@ -57,7 +57,7 @@ type AdminConfig struct {
57
58 // The address to which the admin endpoint's listener should
59 // bind itself. Can be any single network address that can be
60 - // parsed by Caddy. Default: localhost:2019
60 + // parsed by Caddy. Accepts placeholders. Default: localhost:2019
61 Listen string `json:"listen,omitempty"`
62
63 // If true, CORS headers will be emitted, and requests to the
@@ -156,7 +156,7 @@ type IdentityConfig struct {
156 //
157 // EXPERIMENTAL: Subject to change.
158 type RemoteAdmin struct {
159 - // The address on which to start the secure listener.
159 + // The address on which to start the secure listener. Accepts placeholders.
160 // Default: :2021
161 Listen string `json:"listen,omitempty"`
162
@@ -1247,7 +1247,10 @@ func (e APIError) Error() string {
1247 // parseAdminListenAddr extracts a singular listen address from either addr
1248 // or defaultAddr, returning the network and the address of the listener.
1249 func parseAdminListenAddr(addr string, defaultAddr string) (NetworkAddress, error) {
1250 - input := addr
1250 + input, err := NewReplacer().ReplaceOrErr(addr, true, true)
1251 + if err != nil {
1252 + return NetworkAddress{}, fmt.Errorf("replacing listen address: %v", err)
1253 + }
1254 if input == "" {
1255 input = defaultAddr
1256 }