From 6f546b4c21de7f6749b8607aedaa8d2d5c5c6c8f Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 4 Feb 2018 13:48:51 +0100 Subject: [PATCH] Use Cache-Control --- dnscrypt-proxy/proxy.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index aa34e820..9faeffa8 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -10,6 +10,7 @@ import ( "time" "github.com/jedisct1/dlog" + "github.com/pquerna/cachecontrol/cacheobject" "golang.org/x/crypto/curve25519" ) @@ -334,23 +335,16 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str } func ttlFromHTTPResponse(proxy *Proxy, resp *http.Response) *uint32 { - expiresStr, dateStr := resp.Header.Get("Expires"), resp.Header.Get("Date") - if len(expiresStr) == 0 || len(dateStr) == 0 { + cacheControlStr := resp.Header.Get("Cache-Control") + if len(cacheControlStr) == 0 { return nil } - expires, err := http.ParseTime(expiresStr) + cacheControl, err := cacheobject.ParseResponseCacheControl(cacheControlStr) if err != nil { return nil } - date, err := http.ParseTime(dateStr) - if err != nil { - return nil - } - if !expires.After(date) { - return nil - } - foundTTL := uint32(expires.Sub(date).Seconds()) - if foundTTL < proxy.cacheMaxTTL { + foundTTL := uint32(cacheControl.MaxAge) + if foundTTL < proxy.cacheMinTTL { foundTTL = proxy.cacheMinTTL } if foundTTL > proxy.cacheMaxTTL {