Skip to content

Commit

Permalink
feat(favicon): set cache fields for website icon response
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonish committed Sep 2, 2024
1 parent f990d62 commit 8323f05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/pages/favicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ import (

// favicon registers favicon routing.
func favicon(router *gin.Engine) {
router.StaticFile("/favicon.ico", model.FAVICON_FILE)
router.GET("/favicon.ico", func(ctx *gin.Context) {
setCacheHeader(ctx)
ctx.File(model.FAVICON_FILE)
})
}
10 changes: 10 additions & 0 deletions internal/pages/handler.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package pages

import (
"net/http"
"slender/internal/global"
"slender/internal/model"
"slender/internal/redirect"
"slender/internal/validator"
"time"

"github.com/gin-gonic/gin"
)
Expand Down Expand Up @@ -68,3 +70,11 @@ func adminBypasser(ctx *gin.Context) {
return
}
}

// setCacheHeader sets response cache fields.
//
// Default is 24 hours.
func setCacheHeader(c *gin.Context) {
c.Header("Cache-Control", "public, max-age=86400")
c.Header("Expires", time.Now().Add(24*time.Hour).Format(http.TimeFormat))
}

0 comments on commit 8323f05

Please sign in to comment.