From f68e5ae9efbb840f62de8b98804f1ec4d2509660 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Sat, 30 Nov 2024 11:16:07 +0000 Subject: [PATCH] Optimize cache control header assignment in file server --- internal/glance/utils.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/glance/utils.go b/internal/glance/utils.go index 7af45af..9600031 100644 --- a/internal/glance/utils.go +++ b/internal/glance/utils.go @@ -147,10 +147,11 @@ func titleToSlug(s string) string { func fileServerWithCache(fs http.FileSystem, cacheDuration time.Duration) http.Handler { server := http.FileServer(fs) + cacheControlValue := fmt.Sprintf("public, max-age=%d", int(cacheDuration.Seconds())) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // TODO: fix always setting cache control even if the file doesn't exist - w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", int(cacheDuration.Seconds()))) + w.Header().Set("Cache-Control", cacheControlValue) server.ServeHTTP(w, r) }) }