Skip to content

Commit 6f546b4

Browse files
committed
Use Cache-Control
1 parent 6b49470 commit 6f546b4

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

dnscrypt-proxy/proxy.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/jedisct1/dlog"
13+
"github.com/pquerna/cachecontrol/cacheobject"
1314
"golang.org/x/crypto/curve25519"
1415
)
1516

@@ -334,23 +335,16 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
334335
}
335336

336337
func ttlFromHTTPResponse(proxy *Proxy, resp *http.Response) *uint32 {
337-
expiresStr, dateStr := resp.Header.Get("Expires"), resp.Header.Get("Date")
338-
if len(expiresStr) == 0 || len(dateStr) == 0 {
338+
cacheControlStr := resp.Header.Get("Cache-Control")
339+
if len(cacheControlStr) == 0 {
339340
return nil
340341
}
341-
expires, err := http.ParseTime(expiresStr)
342+
cacheControl, err := cacheobject.ParseResponseCacheControl(cacheControlStr)
342343
if err != nil {
343344
return nil
344345
}
345-
date, err := http.ParseTime(dateStr)
346-
if err != nil {
347-
return nil
348-
}
349-
if !expires.After(date) {
350-
return nil
351-
}
352-
foundTTL := uint32(expires.Sub(date).Seconds())
353-
if foundTTL < proxy.cacheMaxTTL {
346+
foundTTL := uint32(cacheControl.MaxAge)
347+
if foundTTL < proxy.cacheMinTTL {
354348
foundTTL = proxy.cacheMinTTL
355349
}
356350
if foundTTL > proxy.cacheMaxTTL {

0 commit comments

Comments
 (0)