summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2021-09-06 23:05:44 +0200
committerGitHub <noreply@github.com>2021-09-06 23:05:44 +0200
commit9fa6bdb64e66f0175d2c3aa74e51f52858e119b9 (patch)
treeba529e6f6ea5079c470042c4ffd45f8997bc57dc /routers
parentcf6d398485473b9c5af413bc05ba61378be9274b (diff)
downloadgitea-9fa6bdb64e66f0175d2c3aa74e51f52858e119b9.tar.gz
gitea-9fa6bdb64e66f0175d2c3aa74e51f52858e119b9.zip
Add Cache-Control to avatar redirects (#16973)
* Add Cache-Control to avatar redirects This does seem to do the trick to make the Avatar redirects cachable in Chrome. In Firefox, it does not seem to work, thought and I found no way to suppress the requests to the original URLs, I even tried setting an Etag to no avail. Related discussion in https://github.com/go-gitea/gitea/issues/16964. Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/user/avatar.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/routers/web/user/avatar.go b/routers/web/user/avatar.go
index 8a5a36e070..2df5c148f7 100644
--- a/routers/web/user/avatar.go
+++ b/routers/web/user/avatar.go
@@ -13,10 +13,16 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
+func cacheableRedirect(ctx *context.Context, location string) {
+ ctx.Resp.Header().Set("Cache-Control", httpcache.GetCacheControl())
+ ctx.Redirect(location)
+}
+
// Avatar redirect browser to user avatar of requested size
func Avatar(ctx *context.Context) {
userName := ctx.Params(":username")
@@ -43,7 +49,7 @@ func Avatar(ctx *context.Context) {
user = models.NewGhostUser()
}
- ctx.Redirect(user.RealSizedAvatarLink(size))
+ cacheableRedirect(ctx, user.RealSizedAvatarLink(size))
}
// AvatarByEmailHash redirects the browser to the appropriate Avatar link
@@ -63,7 +69,7 @@ func AvatarByEmailHash(ctx *context.Context) {
return
}
if len(email) == 0 {
- ctx.Redirect(models.DefaultAvatarLink())
+ cacheableRedirect(ctx, models.DefaultAvatarLink())
return
}
size := ctx.FormInt("size")
@@ -94,5 +100,5 @@ func AvatarByEmailHash(ctx *context.Context) {
}
}
- ctx.Redirect(models.MakeFinalAvatarURL(avatarURL, size))
+ cacheableRedirect(ctx, models.MakeFinalAvatarURL(avatarURL, size))
}