Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
httpcaddyfile: Improve error on matcher declared outside site block (#3431)
Francis Lavoie committed
May 20, 2020 at 12:37 UTC
cc8fb488d360f609d7e3aae773ec80c661505367
2 files changed
+12
caddyconfig/httpcaddyfile/httptype.go
+3
@@ -54,6 +54,9 @@ func (st ServerType) Setup(inputServerBlocks []caddyfile.ServerBlock,
54
originalServerBlocks := make([]serverBlock, 0, len(inputServerBlocks))
55
for i, sblock := range inputServerBlocks {
56
for j, k := range sblock.Keys {
57
+ if j == 0 && strings.HasPrefix(k, "@") {
58
+ return nil, warnings, fmt.Errorf("cannot define a matcher outside of a site block: '%s'", k)
59
+ }
60
if _, ok := sbKeys[k]; ok {
61
return nil, warnings, fmt.Errorf("duplicate site address not allowed: '%s' in %v (site block %d, key %d)", k, sblock.Keys, i, j)
62
}
caddyconfig/httpcaddyfile/httptype_test.go
+9
@@ -57,6 +57,15 @@ func TestMatcherSyntax(t *testing.T) {
57
expectWarn: false,
58
expectError: false,
59
},
60
+ {
61
+ input: `@matcher {
62
+ path /matcher-not-allowed/outside-of-site-block/*
63
+ }
64
+ http://localhost
65
+ `,
66
+ expectWarn: false,
67
+ expectError: true,
68
+ },
69
} {
70
71
adapter := caddyfile.Adapter{