From 1b7ff5d76c7a3c67b6e0f9b51af78d1b227fdea3 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Tue, 18 Jan 2022 13:29:07 -0500 Subject: httpcaddyfile: Add `default_bind` global option (#4531) --- caddyconfig/httpcaddyfile/addresses.go | 6 ++- caddyconfig/httpcaddyfile/options.go | 1 + .../global_options_default_bind.txt | 52 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 caddytest/integration/caddyfile_adapt/global_options_default_bind.txt diff --git a/caddyconfig/httpcaddyfile/addresses.go b/caddyconfig/httpcaddyfile/addresses.go index e2e7771..b33c0f0 100644 --- a/caddyconfig/httpcaddyfile/addresses.go +++ b/caddyconfig/httpcaddyfile/addresses.go @@ -213,7 +213,11 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str lnHosts = append(lnHosts, cfgVal.Value.([]string)...) } if len(lnHosts) == 0 { - lnHosts = []string{""} + if defaultBind, ok := options["default_bind"].(string); ok { + lnHosts = []string{defaultBind} + } else { + lnHosts = []string{""} + } } // use a map to prevent duplication diff --git a/caddyconfig/httpcaddyfile/options.go b/caddyconfig/httpcaddyfile/options.go index 91709cc..016d0df 100644 --- a/caddyconfig/httpcaddyfile/options.go +++ b/caddyconfig/httpcaddyfile/options.go @@ -29,6 +29,7 @@ func init() { RegisterGlobalOption("debug", parseOptTrue) RegisterGlobalOption("http_port", parseOptHTTPPort) RegisterGlobalOption("https_port", parseOptHTTPSPort) + RegisterGlobalOption("default_bind", parseOptSingleString) RegisterGlobalOption("grace_period", parseOptDuration) RegisterGlobalOption("default_sni", parseOptSingleString) RegisterGlobalOption("order", parseOptOrder) diff --git a/caddytest/integration/caddyfile_adapt/global_options_default_bind.txt b/caddytest/integration/caddyfile_adapt/global_options_default_bind.txt new file mode 100644 index 0000000..c34186e --- /dev/null +++ b/caddytest/integration/caddyfile_adapt/global_options_default_bind.txt @@ -0,0 +1,52 @@ +{ + default_bind tcp4/0.0.0.0 +} + +example.com { +} + +example.org:12345 { +} +---------- +{ + "apps": { + "http": { + "servers": { + "srv0": { + "listen": [ + "tcp4/0.0.0.0:12345" + ], + "routes": [ + { + "match": [ + { + "host": [ + "example.org" + ] + } + ], + "terminal": true + } + ] + }, + "srv1": { + "listen": [ + "tcp4/0.0.0.0:443" + ], + "routes": [ + { + "match": [ + { + "host": [ + "example.com" + ] + } + ], + "terminal": true + } + ] + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3