From 8fa3bf785071923f121555235656a77ff60463e9 Mon Sep 17 00:00:00 2001 From: KOUNOIKE Yuusuke Date: Tue, 14 Mar 2017 06:08:03 +0900 Subject: [PATCH] Change from Cache-Control based control to Last-Modified based cache control for _avatar. --- .../core/controller/AccountController.scala | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/scala/gitbucket/core/controller/AccountController.scala b/src/main/scala/gitbucket/core/controller/AccountController.scala index 3d449f84e..86866e5cd 100644 --- a/src/main/scala/gitbucket/core/controller/AccountController.scala +++ b/src/main/scala/gitbucket/core/controller/AccountController.scala @@ -15,6 +15,7 @@ import io.github.gitbucket.scalatra.forms._ import org.apache.commons.io.FileUtils import org.scalatra.i18n.Messages import org.scalatra.BadRequest +import java.util.Date class AccountController extends AccountControllerBase @@ -149,12 +150,17 @@ trait AccountControllerBase extends AccountManagementControllerBase { get("/:userName/_avatar"){ val userName = params("userName") - response.setHeader("Cache-Control", "max-age=3600") - getAccountByUserName(userName).flatMap(_.image).map { image => - RawData(FileUtil.getMimeType(image), new java.io.File(getUserUploadDir(userName), image)) - } getOrElse { - contentType = "image/png" - Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png") + (for { + account <- getAccountByUserName(userName) + image <- account.image + } yield (account, image)) match{ + case Some((account, image)) => + response.setDateHeader("Last-Modified", account.updatedDate.getTime) + RawData(FileUtil.getMimeType(image), new java.io.File(getUserUploadDir(userName), image)) + case None => + contentType = "image/png" + response.setDateHeader("Last-Modified", (new Date(0)).getTime) + Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png") } }