mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user