Move nonwriter to mw/pkg/nonwriter (#948)

Make it its own package as shared between autopath and federation.

Fixes #933
This commit is contained in:
Miek Gieben
2017-08-19 17:28:42 +01:00
committed by GitHub
parent 219a899772
commit 87eb0d39a4
6 changed files with 46 additions and 46 deletions

View File

@@ -36,6 +36,7 @@ import (
"github.com/coredns/coredns/middleware"
"github.com/coredns/coredns/middleware/pkg/dnsutil"
"github.com/coredns/coredns/middleware/pkg/nonwriter"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
@@ -101,7 +102,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms
for i, s := range searchpath {
newQName := base + "." + s
ar.Question[0].Name = newQName
nw := NewNonWriter(w)
nw := nonwriter.New(w)
rcode, err := middleware.NextOrFailure(a.Name(), a.Next, ctx, nw, ar)
if err != nil {

View File

@@ -1,22 +0,0 @@
package autopath
import (
"github.com/miekg/dns"
)
// NonWriter is a type of ResponseWriter that captures the message, but never writes to the client.
type NonWriter struct {
dns.ResponseWriter
Msg *dns.Msg
}
// NewNonWriter makes and returns a new NonWriter.
func NewNonWriter(w dns.ResponseWriter) *NonWriter { return &NonWriter{ResponseWriter: w} }
// WriteMsg records the message, but doesn't write it itself.
func (r *NonWriter) WriteMsg(res *dns.Msg) error {
r.Msg = res
return nil
}
func (r *NonWriter) Write(buf []byte) (int, error) { return len(buf), nil }