diff options
Diffstat (limited to 'caddyconfig')
-rw-r--r-- | caddyconfig/httpcaddyfile/httptype.go | 20 | ||||
-rw-r--r-- | caddyconfig/httpcaddyfile/tlsapp.go | 2 | ||||
-rw-r--r-- | caddyconfig/json5/json5.go | 43 | ||||
-rw-r--r-- | caddyconfig/jsonc/jsonc.go | 49 |
4 files changed, 11 insertions, 103 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype.go b/caddyconfig/httpcaddyfile/httptype.go index 50f3252..0a22807 100644 --- a/caddyconfig/httpcaddyfile/httptype.go +++ b/caddyconfig/httpcaddyfile/httptype.go @@ -319,11 +319,13 @@ func (ServerType) evaluateGlobalOptionsBlock(serverBlocks []serverBlock, options } // hostsFromServerBlockKeys returns a list of all the non-empty hostnames -// found in the keys of the server block sb. If sb has a key that omits -// the hostname (i.e. is a catch-all/empty host), then the returned list -// is empty, because the server block effectively matches ALL hosts. +// found in the keys of the server block sb, unless allowEmpty is true, in +// which case a key with no host (e.g. ":443") will be added to the list as +// an empty string. Otherwise, if allowEmpty is false, and if sb has a key +// that omits the hostname (i.e. is a catch-all/empty host), then the returned +// list is empty, because the server block effectively matches ALL hosts. // The list may not be in a consistent order. -func (st *ServerType) hostsFromServerBlockKeys(sb caddyfile.ServerBlock) ([]string, error) { +func (st *ServerType) hostsFromServerBlockKeys(sb caddyfile.ServerBlock, allowEmpty bool) ([]string, error) { // first get each unique hostname hostMap := make(map[string]struct{}) for _, sblockKey := range sb.Keys { @@ -332,7 +334,7 @@ func (st *ServerType) hostsFromServerBlockKeys(sb caddyfile.ServerBlock) ([]stri return nil, fmt.Errorf("parsing server block key: %v", err) } addr = addr.Normalize() - if addr.Host == "" { + if addr.Host == "" && !allowEmpty { // server block contains a key like ":443", i.e. the host portion // is empty / catch-all, which means to match all hosts return []string{}, nil @@ -408,7 +410,7 @@ func (st *ServerType) serversFromPairings( return nil, fmt.Errorf("server block %v: compiling matcher sets: %v", sblock.block.Keys, err) } - hosts, err := st.hostsFromServerBlockKeys(sblock.block) + hosts, err := st.hostsFromServerBlockKeys(sblock.block, false) if err != nil { return nil, err } @@ -488,14 +490,12 @@ func (st *ServerType) serversFromPairings( LoggerNames: make(map[string]string), } } - hosts, err := st.hostsFromServerBlockKeys(sblock.block) + hosts, err := st.hostsFromServerBlockKeys(sblock.block, true) if err != nil { return nil, err } for _, h := range hosts { - if ncl.name != "" { - srv.Logs.LoggerNames[h] = ncl.name - } + srv.Logs.LoggerNames[h] = ncl.name } } } diff --git a/caddyconfig/httpcaddyfile/tlsapp.go b/caddyconfig/httpcaddyfile/tlsapp.go index 4f72a4a..3b3963f 100644 --- a/caddyconfig/httpcaddyfile/tlsapp.go +++ b/caddyconfig/httpcaddyfile/tlsapp.go @@ -82,7 +82,7 @@ func (st ServerType) buildTLSApp( // get values that populate an automation policy for this block var ap *caddytls.AutomationPolicy - sblockHosts, err := st.hostsFromServerBlockKeys(sblock.block) + sblockHosts, err := st.hostsFromServerBlockKeys(sblock.block, false) if err != nil { return nil, warnings, err } diff --git a/caddyconfig/json5/json5.go b/caddyconfig/json5/json5.go deleted file mode 100644 index 2c86301..0000000 --- a/caddyconfig/json5/json5.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 Matthew Holt and The Caddy Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package json5adapter - -import ( - "encoding/json" - - "github.com/caddyserver/caddy/v2/caddyconfig" - "github.com/ilibs/json5" -) - -func init() { - caddyconfig.RegisterAdapter("json5", Adapter{}) -} - -// Adapter adapts JSON5 to Caddy JSON. -type Adapter struct{} - -// Adapt converts the JSON5 config in body to Caddy JSON. -func (a Adapter) Adapt(body []byte, options map[string]interface{}) (result []byte, warnings []caddyconfig.Warning, err error) { - var decoded interface{} - err = json5.Unmarshal(body, &decoded) - if err != nil { - return - } - result, err = json.Marshal(decoded) - return -} - -// Interface guard -var _ caddyconfig.Adapter = (*Adapter)(nil) diff --git a/caddyconfig/jsonc/jsonc.go b/caddyconfig/jsonc/jsonc.go deleted file mode 100644 index 4f72c05..0000000 --- a/caddyconfig/jsonc/jsonc.go +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2015 Matthew Holt and The Caddy Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package jsoncadapter - -import ( - "encoding/json" - - "github.com/caddyserver/caddy/v2/caddyconfig" - "github.com/muhammadmuzzammil1998/jsonc" -) - -func init() { - caddyconfig.RegisterAdapter("jsonc", Adapter{}) -} - -// Adapter adapts JSON-C to Caddy JSON. -type Adapter struct{} - -// Adapt converts the JSON-C config in body to Caddy JSON. -func (a Adapter) Adapt(body []byte, options map[string]interface{}) (result []byte, warnings []caddyconfig.Warning, err error) { - result = jsonc.ToJSON(body) - - // any errors in the JSON will be - // reported during config load, but - // we can at least warn here that - // it is not valid JSON - if !json.Valid(result) { - warnings = append(warnings, caddyconfig.Warning{ - Message: "Resulting JSON is invalid.", - }) - } - - return -} - -// Interface guard -var _ caddyconfig.Adapter = (*Adapter)(nil) |