diff --git a/plugins/caddy/httpcache_test.go b/plugins/caddy/httpcache_test.go index 7a0483638..8d7f5bd9a 100644 --- a/plugins/caddy/httpcache_test.go +++ b/plugins/caddy/httpcache_test.go @@ -33,6 +33,12 @@ func TestMaxAge(t *testing.T) { if resp2.Header.Get("Cache-Status") != "Souin; hit; ttl=59" { t.Errorf("unexpected Cache-Status header %v", resp2.Header.Get("Cache-Status")) } + + time.Sleep(2 * time.Second) + resp3, _ := tester.AssertGetResponse(`http://localhost:9080/cache-max-age`, 200, "Hello, max-age!") + if resp3.Header.Get("Cache-Status") != "Souin; hit; ttl=57" { + t.Errorf("unexpected Cache-Status header %v", resp2.Header.Get("Cache-Status")) + } } func TestSMaxAge(t *testing.T) { diff --git a/rfc/cacheStatus.go b/rfc/cacheStatus.go index 0ffa6966f..1dcaa95b9 100644 --- a/rfc/cacheStatus.go +++ b/rfc/cacheStatus.go @@ -78,12 +78,12 @@ func manageAge(h *http.Header, ttl time.Duration) { if h.Get(storedTTLHeader) != "" { ttl, _ = time.ParseDuration(h.Get(storedTTLHeader)) h.Del(storedTTLHeader) + cage := correctedInitialAge(utc1, utc2) + age := strconv.Itoa(cage) + h.Set("Age", age) + ttlValue := strconv.Itoa(int(ttl.Seconds()) - cage) + h.Set("Cache-Status", "Souin; hit; ttl="+ttlValue) } - cage := correctedInitialAge(utc1, utc2) - age := strconv.Itoa(cage) - h.Set("Age", age) - ttlValue := strconv.Itoa(int(ttl.Seconds()) - cage) - h.Set("Cache-Status", "Souin; hit; ttl="+ttlValue) } func setMalformedHeader(headers *http.Header, header string) { diff --git a/rfc/transport.go b/rfc/transport.go index 27b27c04f..441728a3c 100644 --- a/rfc/transport.go +++ b/rfc/transport.go @@ -78,9 +78,8 @@ func (t *VaryTransport) SetCache(key string, resp *http.Response) { } if ma > t.ConfigurationURL.TTL.Duration { ma = t.ConfigurationURL.TTL.Duration - } else { - resp.Header.Set(storedTTLHeader, ma.String()) } + resp.Header.Set(storedTTLHeader, ma.String()) if respBytes, err := httputil.DumpResponse(resp, true); e == nil && err == nil { t.Provider.Set(key, respBytes, t.ConfigurationURL, ma) }