diff options
author | 2018-06-27 21:12:27 +0100 | |
---|---|---|
committer | 2018-06-27 21:12:27 +0100 | |
commit | dae506b5638c7309399cb273d7f76bc20ee518dd (patch) | |
tree | 3fe5eb2c2e2d4b7e047fe87ebeccc0e9e7aa5ea4 /core/dnsserver/server_https.go | |
parent | 99287d091c2db4028e54782fd4de43f63ca4b040 (diff) | |
download | coredns-dae506b5638c7309399cb273d7f76bc20ee518dd.tar.gz coredns-dae506b5638c7309399cb273d7f76bc20ee518dd.tar.zst coredns-dae506b5638c7309399cb273d7f76bc20ee518dd.zip |
Fix max-age in http server (#1890)
* Fix max-age in http server
Move the minMsgTTL to dnsutil and rename it MinimalTTL, move some
constants there as well.
Use these new function in server_https to correctly set the max-age
HTTP header.
Fixes: #1823
* Linter
Diffstat (limited to 'core/dnsserver/server_https.go')
-rw-r--r-- | core/dnsserver/server_https.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/core/dnsserver/server_https.go b/core/dnsserver/server_https.go index c9f0da0cd..cf5d08a45 100644 --- a/core/dnsserver/server_https.go +++ b/core/dnsserver/server_https.go @@ -7,6 +7,10 @@ import ( "net" "net/http" "strconv" + "time" + + "github.com/coredns/coredns/plugin/pkg/dnsutil" + "github.com/coredns/coredns/plugin/pkg/response" "github.com/miekg/dns" ) @@ -129,8 +133,11 @@ func (s *ServerHTTPS) ServeHTTP(w http.ResponseWriter, r *http.Request) { buf, _ := dw.Msg.Pack() + mt, _ := response.Typify(dw.Msg, time.Now().UTC()) + age := dnsutil.MinimalTTL(dw.Msg, mt) + w.Header().Set("Content-Type", mimeTypeDOH) - w.Header().Set("Cache-Control", "max-age=128") // TODO(issues/1823): implement proper fix. + w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%f", age.Seconds())) w.Header().Set("Content-Length", strconv.Itoa(len(buf))) w.WriteHeader(http.StatusOK) |