mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-07-05 13:08:10 +02:00
Change from Cache-Control based control to Last-Modified based cache control for _avatar.
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user