Skip to content

Commit 87c31c2

Browse files
authored
Set X-Gitea-Debug header once (#23361) (#23381)
1 parent 54c674c commit 87c31c2

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

Diff for: modules/context/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func APIContexter() func(http.Handler) http.Handler {
244244
}
245245
}
246246

247-
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 0, "no-transform")
247+
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 0, "no-transform")
248248
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
249249

250250
ctx.Data["Context"] = &ctx

Diff for: modules/context/context.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func (ctx *Context) SetServeHeaders(opts *ServeHeaderOptions) {
388388
if duration == 0 {
389389
duration = 5 * time.Minute
390390
}
391-
httpcache.AddCacheControlToHeader(header, duration)
391+
httpcache.SetCacheControlInHeader(header, duration)
392392

393393
if !opts.LastModified.IsZero() {
394394
header.Set("Last-Modified", opts.LastModified.UTC().Format(http.TimeFormat))
@@ -753,7 +753,7 @@ func Contexter(ctx context.Context) func(next http.Handler) http.Handler {
753753
}
754754
}
755755

756-
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 0, "no-transform")
756+
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 0, "no-transform")
757757
ctx.Resp.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
758758

759759
ctx.Data["CsrfToken"] = ctx.csrf.GetToken()

Diff for: modules/httpcache/httpcache.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"code.gitea.io/gitea/modules/setting"
1616
)
1717

18-
// AddCacheControlToHeader adds suitable cache-control headers to response
19-
func AddCacheControlToHeader(h http.Header, maxAge time.Duration, additionalDirectives ...string) {
18+
// SetCacheControlInHeader sets suitable cache-control headers in the response
19+
func SetCacheControlInHeader(h http.Header, maxAge time.Duration, additionalDirectives ...string) {
2020
directives := make([]string, 0, 2+len(additionalDirectives))
2121

2222
// "max-age=0 + must-revalidate" (aka "no-cache") is preferred instead of "no-store"
@@ -31,7 +31,7 @@ func AddCacheControlToHeader(h http.Header, maxAge time.Duration, additionalDire
3131
directives = append(directives, "max-age=0", "private", "must-revalidate")
3232

3333
// to remind users they are using non-prod setting.
34-
h.Add("X-Gitea-Debug", "RUN_MODE="+setting.RunMode)
34+
h.Set("X-Gitea-Debug", "RUN_MODE="+setting.RunMode)
3535
}
3636

3737
h.Set("Cache-Control", strings.Join(append(directives, additionalDirectives...), ", "))
@@ -50,7 +50,7 @@ func HandleTimeCache(req *http.Request, w http.ResponseWriter, fi os.FileInfo) (
5050

5151
// HandleGenericTimeCache handles time-based caching for a HTTP request
5252
func HandleGenericTimeCache(req *http.Request, w http.ResponseWriter, lastModified time.Time) (handled bool) {
53-
AddCacheControlToHeader(w.Header(), setting.StaticCacheTime)
53+
SetCacheControlInHeader(w.Header(), setting.StaticCacheTime)
5454

5555
ifModifiedSince := req.Header.Get("If-Modified-Since")
5656
if ifModifiedSince != "" {
@@ -81,7 +81,7 @@ func HandleGenericETagCache(req *http.Request, w http.ResponseWriter, etag strin
8181
return true
8282
}
8383
}
84-
AddCacheControlToHeader(w.Header(), setting.StaticCacheTime)
84+
SetCacheControlInHeader(w.Header(), setting.StaticCacheTime)
8585
return false
8686
}
8787

@@ -125,6 +125,6 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
125125
}
126126
}
127127
}
128-
AddCacheControlToHeader(w.Header(), setting.StaticCacheTime)
128+
SetCacheControlInHeader(w.Header(), setting.StaticCacheTime)
129129
return false
130130
}

Diff for: routers/install/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func installRecovery(ctx goctx.Context) func(next http.Handler) http.Handler {
6464
"SignedUserName": "",
6565
}
6666

67-
httpcache.AddCacheControlToHeader(w.Header(), 0, "no-transform")
67+
httpcache.SetCacheControlInHeader(w.Header(), 0, "no-transform")
6868
w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
6969

7070
if !setting.IsProd {

Diff for: routers/web/base.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func Recovery(ctx goctx.Context) func(next http.Handler) http.Handler {
158158
store["SignedUserName"] = ""
159159
}
160160

161-
httpcache.AddCacheControlToHeader(w.Header(), 0, "no-transform")
161+
httpcache.SetCacheControlInHeader(w.Header(), 0, "no-transform")
162162
w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
163163

164164
if !setting.IsProd {

Diff for: routers/web/user/avatar.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func cacheableRedirect(ctx *context.Context, location string) {
1717
// here we should not use `setting.StaticCacheTime`, it is pretty long (default: 6 hours)
1818
// we must make sure the redirection cache time is short enough, otherwise a user won't see the updated avatar in 6 hours
1919
// it's OK to make the cache time short, it is only a redirection, and doesn't cost much to make a new request
20-
httpcache.AddCacheControlToHeader(ctx.Resp.Header(), 5*time.Minute)
20+
httpcache.SetCacheControlInHeader(ctx.Resp.Header(), 5*time.Minute)
2121
ctx.Redirect(location)
2222
}
2323

0 commit comments

Comments
 (0)