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

@ -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)