diff --git a/modules/httpcache/httpcache.go b/modules/httpcache/httpcache.go index 311f7215b2..c37ce6c013 100644 --- a/modules/httpcache/httpcache.go +++ b/modules/httpcache/httpcache.go @@ -14,8 +14,8 @@ import ( ) // SetCacheControlInHeader sets suitable cache-control headers in the response -func SetCacheControlInHeader(h http.Header, maxAge time.Duration, additionalDirectives ...string) { - directives := make([]string, 0, 2+len(additionalDirectives)) +func SetCacheControlInHeader(h http.Header, maxAge time.Duration) { + directives := make([]string, 0, 2) // "max-age=0 + must-revalidate" (aka "no-cache") is preferred instead of "no-store" // because browsers may restore some input fields after navigate-back / reload a page. @@ -33,7 +33,7 @@ func SetCacheControlInHeader(h http.Header, maxAge time.Duration, additionalDire h.Set("X-Forgejo-Debug", "RUN_MODE="+setting.RunMode) } - h.Set("Cache-Control", strings.Join(append(directives, additionalDirectives...), ", ")) + h.Set("Cache-Control", strings.Join(directives, ", ")) } func ServeContentWithCacheControl(w http.ResponseWriter, req *http.Request, name string, modTime time.Time, content io.ReadSeeker) { diff --git a/routers/common/errpage.go b/routers/common/errpage.go index 4dc5a58858..19154b4e20 100644 --- a/routers/common/errpage.go +++ b/routers/common/errpage.go @@ -32,7 +32,7 @@ func RenderPanicErrorPage(w http.ResponseWriter, req *http.Request, err any) { routing.UpdatePanicError(req.Context(), err) - httpcache.SetCacheControlInHeader(w.Header(), 0, "no-transform") + httpcache.SetCacheControlInHeader(w.Header(), 0) w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions) tmplCtx := templates.NewContext(req.Context()) diff --git a/services/context/api.go b/services/context/api.go index a6af94dfde..0284783549 100644 --- a/services/context/api.go +++ b/services/context/api.go @@ -293,7 +293,7 @@ func APIContexter() func(http.Handler) http.Handler { ctx.AppendContextValue(apiContextKey, ctx) ctx.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo }) - httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 0, "no-transform") + httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 0) ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions) next.ServeHTTP(ctx.Resp, ctx.Req) diff --git a/services/context/context.go b/services/context/context.go index af5ec26143..d5c4f6fd2a 100644 --- a/services/context/context.go +++ b/services/context/context.go @@ -177,7 +177,7 @@ func Contexter() func(next http.Handler) http.Handler { } }) - httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 0, "no-transform") + httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 0) ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions) ctx.Data["SystemConfig"] = setting.Config()