* server: actually scrub response Did all the worked, hooked it up wrongly :( This also needs test, but those are hard(er) because we only receive packets after they have been decoded; i.e. we never see the wirefmt. Signed-off-by: Miek Gieben <miek@miek.nl> * Add tests Add a test for checking is compression pointers are set in the packet. This also adds an undocumented 'large' feature to the erratic plugin to send large responses that should be compressed. Commenting the Scrub out in server results in: === RUN TestCompressScrub --- FAIL: TestCompressScrub (0.00s) compression_scrub_test.go:41: Expected returned packet to be < 512, got 839 FAIL exit status 1 FAIL github.com/coredns/coredns/test 0.036s Actually checking the size might be easier, but lets be thorough here and check the pointers them selves. Signed-off-by: Miek Gieben <miek@miek.nl> * Fix tests Signed-off-by: Miek Gieben <miek@miek.nl> * plugin erratic: fix e.large always put an rr in the reply, fix e.large in erractic and add test to check for it. Signed-off-by: Miek Gieben <miek@miek.nl>
20 lines
711 B
Go
20 lines
711 B
Go
package request
|
|
|
|
import "github.com/miekg/dns"
|
|
|
|
// ScrubWriter will, when writing the message, call scrub to make it fit the client's buffer.
|
|
type ScrubWriter struct {
|
|
dns.ResponseWriter
|
|
req *dns.Msg // original request
|
|
}
|
|
|
|
// NewScrubWriter returns a new and initialized ScrubWriter.
|
|
func NewScrubWriter(req *dns.Msg, w dns.ResponseWriter) *ScrubWriter { return &ScrubWriter{w, req} }
|
|
|
|
// WriteMsg overrides the default implementation of the underlaying dns.ResponseWriter and calls
|
|
// scrub on the message m and will then write it to the client.
|
|
func (s *ScrubWriter) WriteMsg(m *dns.Msg) error {
|
|
state := Request{Req: s.req, W: s.ResponseWriter}
|
|
n := state.Scrub(m)
|
|
return s.ResponseWriter.WriteMsg(n)
|
|
}
|