middleware/file: correctly parse the stanza (#658)

* middleware/file: correctly parse the stanza

Parsing the file stanza would give precedence to 'transfer' and ignore
other bits if it wasn't specified.

This change fixes the parsing. The actually external CNAME retrieval is
working fine (once the upstream is correctly parsed).

This wasn't caught in tests, because we lack a parsing test for this.

Fixes #657

* Add tests
This commit is contained in:
Miek Gieben
2017-05-03 16:36:41 +01:00
committed by GitHub
parent 4fc1318e28
commit 8eda6c7b9c
3 changed files with 87 additions and 34 deletions

View File

@@ -48,6 +48,7 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
names := []string{}
origins := []string{}
for c.Next() {
if c.Val() == "secondary" {
// secondary [origin]
origins = make([]string, len(c.ServerBlockKeys))
@@ -63,10 +64,18 @@ func secondaryParse(c *caddy.Controller) (file.Zones, error) {
}
for c.NextBlock() {
t, f, e := file.TransferParse(c, true)
if e != nil {
return file.Zones{}, e
t, f := []string{}, []string{}
var e error
switch c.Val() {
case "transfer":
t, _, e = file.TransferParse(c, true)
if e != nil {
return file.Zones{}, e
}
}
for _, origin := range origins {
if t != nil {
z[origin].TransferTo = append(z[origin].TransferTo, t...)