middleware/proxy: implement Exchanger (#480)

By defining and using an proxy.Exchanger interface we make the proxy
more generic and we can then fold back httproxy into proxy.

This overrides #463 and #473 and should make futures extensions rather
trivial

* Add docs that talk about `protocol` and how to set it.
* middleware/proxy: rename New to NewLookup
  It's used as a Lookup mechanism not as a completely new proxy,
  reflect that in the name.
* Set maxfails to 3 by default when looking up names.

Most of the changes have been copied
from https://github.com/johnbelamaric/coredns/pull/1/files
This commit is contained in:
Miek Gieben
2017-01-15 08:12:58 +00:00
committed by GitHub
parent a6d232a622
commit 52e01264e8
25 changed files with 140 additions and 61 deletions

View File

@@ -42,7 +42,7 @@ func TestAuto(t *testing.T) {
log.SetOutput(ioutil.Discard)
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "www.example.org.", dns.TypeA)
@@ -108,7 +108,7 @@ func TestAutoNonExistentZone(t *testing.T) {
}
defer i.Stop()
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
@@ -155,7 +155,7 @@ func TestAutoAXFR(t *testing.T) {
time.Sleep(1100 * time.Millisecond) // wait for it to be picked up
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
m := new(dns.Msg)
m.SetAxfr("example.org.")
state := request.Request{W: &test.ResponseWriter{}, Req: m}

View File

@@ -56,7 +56,7 @@ func TestLookupCache(t *testing.T) {
log.SetOutput(ioutil.Discard)
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
@@ -65,7 +65,7 @@ func TestLookupCache(t *testing.T) {
}
// expect answer section with A record in it
if len(resp.Answer) == 0 {
t.Error("Expected to at least one RR in the answer section, got none")
t.Fatal("Expected to at least one RR in the answer section, got none")
}
ttl := resp.Answer[0].Header().Ttl

View File

@@ -57,7 +57,7 @@ func TestLookupDS(t *testing.T) {
log.SetOutput(ioutil.Discard)
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &mtest.ResponseWriter{}, Req: new(dns.Msg)}
for _, tc := range dsTestCases {

View File

@@ -47,7 +47,7 @@ func TestEtcdCacheAndDebug(t *testing.T) {
defer delete(ctx, t, etc, serv.Key)
}
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "b.example.skydns.test.", dns.TypeA)

View File

@@ -66,15 +66,14 @@ func TestEtcdStubAndProxyLookup(t *testing.T) {
defer delete(ctx, t, etc, serv.Key)
}
p := proxy.New([]string{udp}) // use udp port from the server
p := proxy.NewLookup([]string{udp}) // use udp port from the server
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.com.", dns.TypeA)
if err != nil {
t.Error("Expected to receive reply, but didn't")
return
t.Fatalf("Expected to receive reply, but didn't", err)
}
if len(resp.Answer) == 0 {
t.Error("Expected to at least one RR in the answer section, got none")
t.Fatalf("Expected to at least one RR in the answer section, got none")
}
if resp.Answer[0].Header().Rrtype != dns.TypeA {
t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)

View File

@@ -42,7 +42,7 @@ example.net:0 {
}
defer i.Stop()
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)

View File

@@ -33,7 +33,7 @@ func TestProxyErratic(t *testing.T) {
}
defer backend.Stop()
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
// We do one lookup that should not time out.

View File

@@ -38,7 +38,7 @@ func TestLookupProxy(t *testing.T) {
log.SetOutput(ioutil.Discard)
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
resp, err := p.Lookup(state, "example.org.", dns.TypeA)
if err != nil {
@@ -82,7 +82,7 @@ func BenchmarkLookupProxy(b *testing.B) {
log.SetOutput(ioutil.Discard)
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
b.ResetTimer()

View File

@@ -38,7 +38,7 @@ func TestLookupWildcard(t *testing.T) {
log.SetOutput(ioutil.Discard)
p := proxy.New([]string{udp})
p := proxy.NewLookup([]string{udp})
state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
for _, lookup := range []string{"a.w.example.org.", "a.a.w.example.org."} {