Chore: doh request should with id 0 (#1660)

This commit is contained in:
beyondkmp 2021-10-07 22:57:55 +08:00 committed by GitHub
parent 66cb0b1218
commit 1996bef9e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -28,13 +28,19 @@ func (dc *dohClient) Exchange(m *D.Msg) (msg *D.Msg, err error) {
} }
func (dc *dohClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) { func (dc *dohClient) ExchangeContext(ctx context.Context, m *D.Msg) (msg *D.Msg, err error) {
req, err := dc.newRequest(m) // https://datatracker.ietf.org/doc/html/rfc8484#section-4.1
// In order to maximize cache friendliness, SHOULD use a DNS ID of 0 in every DNS request.
newM := *m
newM.Id = 0
req, err := dc.newRequest(&newM)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req = req.WithContext(ctx) req = req.WithContext(ctx)
return dc.doRequest(req) msg, err = dc.doRequest(req)
msg.Id = m.Id
return
} }
// newRequest returns a new DoH request given a dns.Msg. // newRequest returns a new DoH request given a dns.Msg.