@@ -44,6 +44,8 @@ type ResponseWriter interface {
4444 LocalAddr () net.Addr
4545 // RemoteAddr returns the net.Addr of the client that sent the current request.
4646 RemoteAddr () net.Addr
47+ // Network returns the value of the Net field of the Server (e.g., "tcp", "tcp-tls").
48+ Network () string
4749 // WriteMsg writes a reply back to the client.
4850 WriteMsg (* Msg ) error
4951 // Write writes a raw buffer back to the client.
@@ -77,6 +79,7 @@ type response struct {
7779 udpSession * SessionUDP // oob data to get egress interface right
7880 pcSession net.Addr // address to use when writing to a generic net.PacketConn
7981 writer Writer // writer to output the raw DNS bits
82+ network string // corresponding Server.Net value
8083}
8184
8285// handleRefused returns a HandlerFunc that returns REFUSED for every request it gets.
@@ -557,7 +560,7 @@ func (srv *Server) serveUDP(l net.PacketConn) error {
557560
558561// Serve a new TCP connection.
559562func (srv * Server ) serveTCPConn (wg * sync.WaitGroup , rw net.Conn ) {
560- w := & response {tsigProvider : srv .tsigProvider (), tcp : rw }
563+ w := & response {tsigProvider : srv .tsigProvider (), tcp : rw , network : srv . Net }
561564 if srv .DecorateWriter != nil {
562565 w .writer = srv .DecorateWriter (w )
563566 } else {
@@ -612,7 +615,7 @@ func (srv *Server) serveTCPConn(wg *sync.WaitGroup, rw net.Conn) {
612615
613616// Serve a new UDP request.
614617func (srv * Server ) serveUDPPacket (wg * sync.WaitGroup , m []byte , u net.PacketConn , udpSession * SessionUDP , pcSession net.Addr ) {
615- w := & response {tsigProvider : srv .tsigProvider (), udp : u , udpSession : udpSession , pcSession : pcSession }
618+ w := & response {tsigProvider : srv .tsigProvider (), udp : u , udpSession : udpSession , pcSession : pcSession , network : srv . Net }
616619 if srv .DecorateWriter != nil {
617620 w .writer = srv .DecorateWriter (w )
618621 } else {
@@ -818,6 +821,9 @@ func (w *response) RemoteAddr() net.Addr {
818821 }
819822}
820823
824+ // Network implements the ResponseWriter.Network method.
825+ func (w * response ) Network () string { return w .network }
826+
821827// TsigStatus implements the ResponseWriter.TsigStatus method.
822828func (w * response ) TsigStatus () error { return w .tsigStatus }
823829
0 commit comments