middleware/cache: cache 0 will be capped at 5 (#408)

* middleware/cache: cache 0 will be capped at 5

cache 0 would return TTL=0 records, up that to the documented minimum of
5 seconds.

* middleware/cache: check for 0 TTL

Handle 0 TTL differently and return an error, we might need to
special case this in the future.
This commit is contained in:
Miek Gieben
2016-11-09 10:01:26 +00:00
committed by GitHub
parent da742ed596
commit 6abbe231e5
5 changed files with 27 additions and 6 deletions

View File

@@ -63,9 +63,6 @@ func (i *item) toMsg(m *dns.Msg) *dns.Msg {
m1.Extra = i.Extra
ttl := int(i.origTTL) - int(time.Now().UTC().Sub(i.stored).Seconds())
if ttl < int(minTTL.Seconds()) {
ttl = int(minTTL.Seconds())
}
setMsgTTL(m1, uint32(ttl))
return m1
}
@@ -75,8 +72,13 @@ func (i *item) expired(now time.Time) bool {
return ttl < 0
}
// setMsgTTL sets the ttl on all RRs in all sections.
// setMsgTTL sets the ttl on all RRs in all sections. If ttl is smaller than minTTL
// that value is used.
func setMsgTTL(m *dns.Msg, ttl uint32) {
if ttl < minTTL {
ttl = minTTL
}
for _, r := range m.Answer {
r.Header().Ttl = ttl
}