middleware/proxy: fix except keyword (#505)

Fix the except keyword usage - the config would allow it, but it was
not enforced in the code.
Turns out that **FROM** was also not enforced, fix both, by (basically)
copying the code from Caddy.

Update the README and tests.

Locally test as well, shows that this works:

~~~
.:1053 {
    proxy miek.nl 8.8.8.8:53 {
        except a.miek.nl
    }
    proxy a.miek.nl 8.8.4.4:53

    errors stdout
    log stdout
}
~~~

And gives the desired results, not having a proxy line for `a.miek.nl`
results in a SERVFAIL (as expected).

Fixes #502
This commit is contained in:
Miek Gieben
2017-02-07 18:01:16 +00:00
committed by GitHub
parent e8ebcd3cfd
commit dbe1b2510d
5 changed files with 43 additions and 16 deletions

View File

@@ -46,7 +46,7 @@ func NewStaticUpstreams(c *caddyfile.Dispenser) ([]Upstream, error) {
var upstreams []Upstream
for c.Next() {
upstream := &staticUpstream{
from: "",
from: ".",
Hosts: nil,
Policy: &Random{},
Spray: nil,
@@ -280,12 +280,13 @@ func (u *staticUpstream) Select() *UpstreamHost {
return u.Spray.Select(pool)
}
func (u *staticUpstream) IsAllowedPath(name string) bool {
func (u *staticUpstream) IsAllowedDomain(name string) bool {
for _, ignoredSubDomain := range u.IgnoredSubDomains {
if dns.Name(name) == dns.Name(u.From()) {
return true
}
if middleware.Name(name).Matches(ignoredSubDomain + u.From()) {
if middleware.Name(ignoredSubDomain).Matches(name) {
return false
}
}