mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-04 02:01:07 +01:00 
			
		
		
		
	Ditch our truncation code and use the upstream one in miekg/dns. This saves code on our end, end upstream is also more efficient as every RR is Len-ed only once. With our bin-search this is not guaranteed. Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			22 lines
		
	
	
		
			725 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			725 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 underlying 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}
 | 
						|
	state.SizeAndDo(m)
 | 
						|
	state.Scrub(m)
 | 
						|
	return s.ResponseWriter.WriteMsg(m)
 | 
						|
}
 |