diff --git a/gateway/gateway_test.go b/gateway/gateway_test.go index d48334b92..5c309a571 100644 --- a/gateway/gateway_test.go +++ b/gateway/gateway_test.go @@ -130,9 +130,9 @@ func TestHeaders(t *testing.T) { path string cacheControl string }{ - {"/ipns/example.net/", "public, max-age=30"}, // As generated directory listing - {"/ipns/example.com/", "public, max-age=55"}, // As generated directory listing (different) - {"/ipns/unknown.com/", ""}, // As generated directory listing (unknown) + {"/ipns/example.net/", "public, max-age=30, stale-while-revalidate=2678400"}, // As generated directory listing + {"/ipns/example.com/", "public, max-age=55, stale-while-revalidate=2678400"}, // As generated directory listing (different) + {"/ipns/unknown.com/", ""}, // As generated directory listing (unknown TTL) {"/ipns/example.net/foo/", "public, max-age=30"}, // As index.html directory listing {"/ipns/example.net/foo/index.html", "public, max-age=30"}, // As deserialized UnixFS file {"/ipns/example.net/?format=raw", "public, max-age=30"}, // As Raw block diff --git a/gateway/handler_unixfs_dir.go b/gateway/handler_unixfs_dir.go index 1878e682d..6f9f856d1 100644 --- a/gateway/handler_unixfs_dir.go +++ b/gateway/handler_unixfs_dir.go @@ -140,7 +140,7 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r * if rq.ttl > 0 { // Use known TTL from IPNS Record or DNSLink TXT Record w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d, stale-while-revalidate=2678400", int(rq.ttl.Seconds()))) - } else { + } else if !rq.contentPath.Mutable() { // Cache for 1 week, serve stale cache for up to a month // (style of generated HTML may change, should not be cached forever) w.Header().Set("Cache-Control", "public, max-age=604800, stale-while-revalidate=2678400")