mirror of
https://github.com/coredns/coredns.git
synced 2025-11-14 07:52:17 -05:00
Remove the word middleware (#1067)
* Rename middleware to plugin first pass; mostly used 'sed', few spots where I manually changed text. This still builds a coredns binary. * fmt error * Rename AddMiddleware to AddPlugin * Readd AddMiddleware to remain backwards compat
This commit is contained in:
49
plugin/dnssec/responsewriter.go
Normal file
49
plugin/dnssec/responsewriter.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package dnssec
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// ResponseWriter sign the response on the fly.
|
||||
type ResponseWriter struct {
|
||||
dns.ResponseWriter
|
||||
d Dnssec
|
||||
}
|
||||
|
||||
// WriteMsg implements the dns.ResponseWriter interface.
|
||||
func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
// By definition we should sign anything that comes back, we should still figure out for
|
||||
// which zone it should be.
|
||||
state := request.Request{W: d.ResponseWriter, Req: res}
|
||||
|
||||
qname := state.Name()
|
||||
zone := plugin.Zones(d.d.zones).Matches(qname)
|
||||
if zone == "" {
|
||||
return d.ResponseWriter.WriteMsg(res)
|
||||
}
|
||||
|
||||
if state.Do() {
|
||||
res = d.d.Sign(state, zone, time.Now().UTC())
|
||||
|
||||
cacheSize.WithLabelValues("signature").Set(float64(d.d.cache.Len()))
|
||||
}
|
||||
state.SizeAndDo(res)
|
||||
|
||||
return d.ResponseWriter.WriteMsg(res)
|
||||
}
|
||||
|
||||
// Write implements the dns.ResponseWriter interface.
|
||||
func (d *ResponseWriter) Write(buf []byte) (int, error) {
|
||||
log.Printf("[WARNING] Dnssec called with Write: not signing reply")
|
||||
n, err := d.ResponseWriter.Write(buf)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Hijack implements the dns.ResponseWriter interface.
|
||||
func (d *ResponseWriter) Hijack() { d.ResponseWriter.Hijack() }
|
||||
Reference in New Issue
Block a user