From 2eed62f1e2a985f5d522899f27aafd9f227f1a2b Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 4 Feb 2018 12:39:33 +0100 Subject: [PATCH] Add a setMaxTTL() function Will be useful to interprete HTTP cache headers in DoH --- dnscrypt-proxy/dnsutils.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dnscrypt-proxy/dnsutils.go b/dnscrypt-proxy/dnsutils.go index 6ee90b7c..0fc217d1 100644 --- a/dnscrypt-proxy/dnsutils.go +++ b/dnscrypt-proxy/dnsutils.go @@ -73,3 +73,21 @@ func getMinTTL(msg *dns.Msg, minTTL uint32, maxTTL uint32, negCacheMinTTL uint32 } return time.Duration(ttl) * time.Second } + +func setMaxTTL(msg *dns.Msg, ttl uint32) { + for _, rr := range msg.Answer { + if ttl < rr.Header().Ttl { + rr.Header().Ttl = ttl + } + } + for _, rr := range msg.Ns { + if ttl < rr.Header().Ttl { + rr.Header().Ttl = ttl + } + } + for _, rr := range msg.Extra { + if ttl < rr.Header().Ttl { + rr.Header().Ttl = ttl + } + } +}