mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
Added minimal-responses plugin (#4417)
* Added minimal-responses plugin Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Removed unnecessary comments * Updated tests Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Reformated imports Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Updated package name Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Removed unnecessary comments Co-authored-by: Miek Gieben <miek@miek.nl> * Added changes Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * updated Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Updated comment for NextOrFailure Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Updated to test.Case for testing Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> * Formated imports using goimports Signed-off-by: Soumya Ghosh Dastidar <gdsoumya@gmail.com> Co-authored-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
committed by
GitHub
parent
74ef6e00f1
commit
7651e6c4de
54
plugin/minimal/minimal.go
Normal file
54
plugin/minimal/minimal.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package minimal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/pkg/nonwriter"
|
||||
"github.com/coredns/coredns/plugin/pkg/response"
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// minimalHandler implements the plugin.Handler interface.
|
||||
type minimalHandler struct {
|
||||
Next plugin.Handler
|
||||
}
|
||||
|
||||
func (m *minimalHandler) Name() string { return "minimal" }
|
||||
|
||||
func (m *minimalHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
nw := nonwriter.New(w)
|
||||
|
||||
rcode, err := plugin.NextOrFailure(m.Name(), m.Next, ctx, nw, r)
|
||||
if err != nil {
|
||||
return rcode, err
|
||||
}
|
||||
|
||||
ty, _ := response.Typify(nw.Msg, time.Now().UTC())
|
||||
cl := response.Classify(ty)
|
||||
|
||||
// if response is Denial or Error pass through also if the type is Delegation pass through
|
||||
if cl == response.Denial || cl == response.Error || ty == response.Delegation {
|
||||
w.WriteMsg(nw.Msg)
|
||||
return 0, nil
|
||||
}
|
||||
if ty != response.NoError {
|
||||
w.WriteMsg(nw.Msg)
|
||||
return 0, plugin.Error("minimal", fmt.Errorf("unhandled response type %q for %q", ty, nw.Msg.Question[0].Name))
|
||||
}
|
||||
|
||||
// copy over the original Msg params, deep copy not required as RRs are not modified
|
||||
d := &dns.Msg{
|
||||
MsgHdr: nw.Msg.MsgHdr,
|
||||
Compress: nw.Msg.Compress,
|
||||
Question: nw.Msg.Question,
|
||||
Answer: nw.Msg.Answer,
|
||||
Ns: nil,
|
||||
Extra: nil,
|
||||
}
|
||||
|
||||
w.WriteMsg(d)
|
||||
return 0, nil
|
||||
}
|
||||
Reference in New Issue
Block a user