mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-17 12:58:51 +08:00
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:
parent
ef6d8bb17b
commit
9370bdb5ac
1 changed files with 2 additions and 3 deletions
|
|
@ -2,7 +2,6 @@ package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -33,7 +32,7 @@ func setWebStatic(rootRouter *gin.RouterGroup) {
|
||||||
RegisterImages(rootRouter)
|
RegisterImages(rootRouter)
|
||||||
setStaticResource(rootRouter)
|
setStaticResource(rootRouter)
|
||||||
rootRouter.GET("/assets/*filepath", func(c *gin.Context) {
|
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] == '/' {
|
if c.Request.URL.Path[len(c.Request.URL.Path)-1] == '/' {
|
||||||
c.AbortWithStatus(http.StatusForbidden)
|
c.AbortWithStatus(http.StatusForbidden)
|
||||||
return
|
return
|
||||||
|
|
@ -137,7 +136,7 @@ func RegisterImages(rootRouter *gin.RouterGroup) {
|
||||||
|
|
||||||
func setStaticResource(rootRouter *gin.RouterGroup) {
|
func setStaticResource(rootRouter *gin.RouterGroup) {
|
||||||
rootRouter.GET("/api/v2/static/*filename", func(c *gin.Context) {
|
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")
|
filename := c.Param("filename")
|
||||||
filePath := "static" + filename
|
filePath := "static" + filename
|
||||||
data, err := web.Static.ReadFile(filePath)
|
data, err := web.Static.ReadFile(filePath)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue