-
Notifications
You must be signed in to change notification settings - Fork 65
/
response-minimize.go
36 lines (30 loc) · 946 Bytes
/
response-minimize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package rdns
import (
"github.com/miekg/dns"
)
// ResponseMinimize is a resolver that strips Extra and Authority records
// from responses, leaving just the answer records.
type ResponseMinimize struct {
id string
resolver Resolver
}
var _ Resolver = &ResponseMinimize{}
// NewResponseMinimize returns a new instance of a response minimizer.
func NewResponseMinimize(id string, resolver Resolver) *ResponseMinimize {
return &ResponseMinimize{id: id, resolver: resolver}
}
// Resolve a DNS query with the upstream resolver and strip out any extra or NS
// records in the response.
func (r *ResponseMinimize) Resolve(q *dns.Msg, ci ClientInfo) (*dns.Msg, error) {
answer, err := r.resolver.Resolve(q, ci)
if err != nil || answer == nil {
return answer, err
}
logger(r.id, q, ci).Debug("stripping response")
answer.Extra = nil
answer.Ns = nil
return answer, nil
}
func (r *ResponseMinimize) String() string {
return r.id
}