fix: remove "no-transfrom" from the cache-control header (#37985)
Cloudflare has officially removed the "auto-minify" feature https://community.cloudflare.com/t/655677, so we don't need such option anymore. Fix #34521
This commit is contained in:
@@ -15,9 +15,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CacheControlOptions struct {
|
type CacheControlOptions struct {
|
||||||
IsPublic bool
|
IsPublic bool
|
||||||
MaxAge time.Duration
|
MaxAge time.Duration
|
||||||
NoTransform bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetCacheControlInHeader sets suitable cache-control headers in the response
|
// SetCacheControlInHeader sets suitable cache-control headers in the response
|
||||||
@@ -38,25 +37,19 @@ func SetCacheControlInHeader(h http.Header, opts *CacheControlOptions) {
|
|||||||
directives = append(directives, "max-age=0", publicPrivate, "must-revalidate")
|
directives = append(directives, "max-age=0", publicPrivate, "must-revalidate")
|
||||||
h.Set("X-Gitea-Debug", fmt.Sprintf("RUN_MODE=%v, MaxAge=%s", setting.RunMode, opts.MaxAge))
|
h.Set("X-Gitea-Debug", fmt.Sprintf("RUN_MODE=%v, MaxAge=%s", setting.RunMode, opts.MaxAge))
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.NoTransform {
|
|
||||||
directives = append(directives, "no-transform")
|
|
||||||
}
|
|
||||||
h.Set("Cache-Control", strings.Join(directives, ", "))
|
h.Set("Cache-Control", strings.Join(directives, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CacheControlForPublicStatic() *CacheControlOptions {
|
func CacheControlForPublicStatic() *CacheControlOptions {
|
||||||
return &CacheControlOptions{
|
return &CacheControlOptions{
|
||||||
IsPublic: true,
|
IsPublic: true,
|
||||||
MaxAge: setting.StaticCacheTime,
|
MaxAge: setting.StaticCacheTime,
|
||||||
NoTransform: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CacheControlForPrivateStatic() *CacheControlOptions {
|
func CacheControlForPrivateStatic() *CacheControlOptions {
|
||||||
return &CacheControlOptions{
|
return &CacheControlOptions{
|
||||||
MaxAge: setting.StaticCacheTime,
|
MaxAge: setting.StaticCacheTime,
|
||||||
NoTransform: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ func TestHandleGenericETagCache(t *testing.T) {
|
|||||||
matchedEtag := `"matched-etag"`
|
matchedEtag := `"matched-etag"`
|
||||||
lastModifiedTime := new(time.Date(2021, time.January, 2, 15, 4, 5, 0, time.FixedZone("test-zone", 8*3600)))
|
lastModifiedTime := new(time.Date(2021, time.January, 2, 15, 4, 5, 0, time.FixedZone("test-zone", 8*3600)))
|
||||||
lastModified := lastModifiedTime.UTC().Format(http.TimeFormat)
|
lastModified := lastModifiedTime.UTC().Format(http.TimeFormat)
|
||||||
cacheControl := "max-age=0, private, must-revalidate, no-transform"
|
cacheControl := "max-age=0, private, must-revalidate"
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
name string
|
name string
|
||||||
reqHeaders map[string]string
|
reqHeaders map[string]string
|
||||||
|
|||||||
@@ -94,9 +94,8 @@ func ServeSetHeaders(w http.ResponseWriter, opts ServeHeaderOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
httpcache.SetCacheControlInHeader(header, &httpcache.CacheControlOptions{
|
httpcache.SetCacheControlInHeader(header, &httpcache.CacheControlOptions{
|
||||||
IsPublic: opts.CacheIsPublic,
|
IsPublic: opts.CacheIsPublic,
|
||||||
MaxAge: opts.CacheDuration,
|
MaxAge: opts.CacheDuration,
|
||||||
NoTransform: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if !opts.LastModified.IsZero() {
|
if !opts.LastModified.IsZero() {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func renderServerErrorPage(w http.ResponseWriter, req *http.Request, respCode in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpcache.SetCacheControlInHeader(w.Header(), &httpcache.CacheControlOptions{NoTransform: true})
|
httpcache.SetCacheControlInHeader(w.Header(), &httpcache.CacheControlOptions{})
|
||||||
tmplCtx := context.NewTemplateContextForWeb(reqctx.FromContext(req.Context()), req, middleware.Locale(w, req))
|
tmplCtx := context.NewTemplateContextForWeb(reqctx.FromContext(req.Context()), req, middleware.Locale(w, req))
|
||||||
w.WriteHeader(respCode)
|
w.WriteHeader(respCode)
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ func APIContexter() func(http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), &httpcache.CacheControlOptions{NoTransform: true})
|
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), &httpcache.CacheControlOptions{})
|
||||||
next.ServeHTTP(ctx.Resp, ctx.Req)
|
next.ServeHTTP(ctx.Resp, ctx.Req)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ func Contexter() func(next http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), &httpcache.CacheControlOptions{NoTransform: true})
|
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), &httpcache.CacheControlOptions{})
|
||||||
|
|
||||||
ctx.Data["SystemConfig"] = setting.Config()
|
ctx.Data["SystemConfig"] = setting.Config()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user