Ignore the Cache-Control: max-age header

What's in the DNS packet is a better source of truth.

There was also an inconsistency between the TTL from the
max-age header (as returned in a response that wasn't cached) and
a response from the cache (using TTLs from the DNS packet).

So, just use what's in the packet.

Reported by @vavrusam, thanks!
This commit is contained in:
Frank Denis 2018-04-01 21:41:36 +02:00
parent 2dedd3a314
commit e210fc537e

View file

@ -5,13 +5,11 @@ import (
"io/ioutil"
"math/rand"
"net"
"net/http"
"sync/atomic"
"time"
"github.com/jedisct1/dlog"
clocksmith "github.com/jedisct1/go-clocksmith"
"github.com/pquerna/cachecontrol/cacheobject"
"golang.org/x/crypto/curve25519"
)
@ -304,7 +302,6 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
if len(response) >= MinDNSPacketSize {
SetTransactionID(response, tid)
}
ttl = ttlFromHTTPResponse(proxy, resp)
} else {
dlog.Fatal("Unsupported protocol")
}
@ -347,25 +344,6 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
}
}
func ttlFromHTTPResponse(proxy *Proxy, resp *http.Response) *uint32 {
cacheControlStr := resp.Header.Get("Cache-Control")
if len(cacheControlStr) == 0 {
return nil
}
cacheControl, err := cacheobject.ParseResponseCacheControl(cacheControlStr)
if err != nil {
return nil
}
foundTTL := uint32(cacheControl.MaxAge)
if foundTTL < proxy.cacheMinTTL {
foundTTL = proxy.cacheMinTTL
}
if foundTTL > proxy.cacheMaxTTL {
foundTTL = proxy.cacheMaxTTL
}
return &foundTTL
}
func NewProxy() Proxy {
return Proxy{
serversInfo: ServersInfo{lbStrategy: DefaultLBStrategy},