fix: Update Cache-Control headers for static resources in router (#11020)

* fix: Update Cache-Control headers for static resources in router

* chore: Remove Cache-Control header from static resource response in router
This commit is contained in:
KOMATA 2025-11-21 15:47:48 +08:00 committed by GitHub
parent ef6d8bb17b
commit 9370bdb5ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,7 +2,6 @@ package router
import (
"encoding/base64"
"fmt"
"io"
"net/http"
"os"
@ -33,7 +32,7 @@ func setWebStatic(rootRouter *gin.RouterGroup) {
RegisterImages(rootRouter)
setStaticResource(rootRouter)
rootRouter.GET("/assets/*filepath", func(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", fmt.Sprintf("private, max-age=%d", 2628000))
c.Writer.Header().Set("Cache-Control", "private, max-age=2628000, immutable")
if c.Request.URL.Path[len(c.Request.URL.Path)-1] == '/' {
c.AbortWithStatus(http.StatusForbidden)
return
@ -137,7 +136,7 @@ func RegisterImages(rootRouter *gin.RouterGroup) {
func setStaticResource(rootRouter *gin.RouterGroup) {
rootRouter.GET("/api/v2/static/*filename", func(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", fmt.Sprintf("private, max-age=%d", 2628000))
c.Writer.Header().Set("Cache-Control", "private, max-age=2628000")
filename := c.Param("filename")
filePath := "static" + filename
data, err := web.Static.ReadFile(filePath)