mirror of
https://github.com/coredns/coredns.git
synced 2025-11-13 15:32:24 -05:00
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:
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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."} {
|
||||
|
||||
Reference in New Issue
Block a user